First up in the weaponImage datablock, create a new flag to check for raycast, this could be an int on how much range to check for, but here I'm going to keep it simple and just use it as a bool.
datablock ShapeBaseImageData(YourWeaponImage) { //... rayTest = 1; //... };In scripts/server/weapon.cs onFIre() function:
function WeaponImage::onFire(%this, %obj, %slot) { //echo("\c4WeaponImage::onFire( "@%this.getName()@", "@%obj.client.nameBase@", "@%slot@" )"); // Make sure we have valid data if (!isObject(%this.projectile)) { error("WeaponImage::onFire() - Invalid projectile datablock"); return; } %doRay = %this.rayTest;//<---------yorks new //... // Add player's velocity %muzzleVelocity = VectorAdd( VectorScale(%muzzleVector, %this.projectile.muzzleVelocity), VectorScale(%objectVelocity, %this.projectile.velInheritFactor)); //yorks new in here! start. if(%doRay == 1) { //use the 2m raycast to check for hits %masks = $TypeMasks::ShapeBaseObjectType;//standard projectile collison mask in projectile.cs %testDist = VectorAdd(%obj.getMuzzlePoint(%slot), VectorScale(%muzzleVector, 2)); %hit = containerRayCast(%eyePoint, %testDist, %masks, %obj); if(%hit != 0) { //hit something, find out what and resolve damage %target = firstWord(%hit); //echo("target hit = " @ %target); %pos = getWords(%hit, 1, 3); %rot = getWords(%hit, 4, 6); if (%target.getType() & ($TypeMasks::ShapeBaseObjectType)) %target.damage(%obj, %pos, %projectile.directDamage, %projectile.damageType); //you might also want to spawn explosions or decals here or do another check for static/terrains or something %decal = %projectile.decal; %explode = %projectile.explosion; %blast = new explosion() { dataBlock = %explode; position = %pos; rotation = %rot; }; MissionCleanup.add(%blast); decalManagerAddDecal(%pos, %rot, 0, 1, %decal, false); return;//no need to spawn a projectile now } } //nothing found in the way, so spawn the projectile as standard //yorks end. // Create the projectile object %p = new (%this.projectileType)() { dataBlock = %this.projectile; initialVelocity = %muzzleVelocity; initialPosition = %obj.getMuzzlePoint(%slot); sourceObject = %obj; sourceSlot = %slot; client = %obj.client; sourceClass = %obj.getClassName(); }; MissionCleanup.add(%p); } }