What you want is probably this. I used the standard bullet as an example and added random damage.
It would be nice if you didnt just copy the code. Please try to understand how it works and learn from it.
I didn't write it so you could ask a similar question next week.
// ***********************************************************
//
// PROJECTILE: Bullet
//
// ***********************************************************
//
// bullet construction
//
function bulletConstruct(proj)
{
// hit scan type projectile
proj.setting.hitScan=true;
// speed
proj.speed.maxHitScanDistance=150000;
// the damage
proj.action.damage=5;
proj.action.collision=true;
// decal (for hitting map)
proj.mark.on=true;
proj.mark.name="mark_normal";
proj.mark.size=100;
proj.mark.alpha=0.55;
}
function bulletSpawn(proj) {
//this function is called when the projectile is spawned
//it sets the damage to a random number between 1 and 100
var randomDamage = utility.random.getInteger(1,100); //a random number is generated
proj.action.damage = randomDamage; //the damage is changed
//you could put it all in one line like this
//proj.action.damage = utility.random.getInteger(1,100);
//but its a bit harder to read, in my opinion
}
//
// bullet hit
//
function bulletHit(proj)
{
var vct;
vct=proj.hit.ejectVector;
spawn.particleMoving(proj.position.x,proj.position.z,proj.position.y,parseInt(vct.x*5),parseInt(vct.z*5),parseInt(vct.y*5),'Gun Hit');
//if you uncomment this line, it will tell you how much damage was done
//iface.console.write("I just did "+proj.action.damage+" damage!")
proj.action.destroy();
}
//
// events
//
function event(proj,mainEvent,subEvent,eventId,tick)
{
switch (mainEvent) {
case DIM3_EVENT_CONSTRUCT:
bulletConstruct(proj);
return;
case DIM3_EVENT_SPAWN: //This calls the bulletSpawn function when the bullet is spawned
bulletSpawn(proj); // <- here
return;
case DIM3_EVENT_HIT:
bulletHit(proj);
return;
}
}