Author Topic: randomizing weapon damage  (Read 370 times)

twproductions

  • Newbie
  • *
  • Posts: 15
    • View Profile
randomizing weapon damage
« on: January 28, 2010, 09:17:18 AM »
hi im sorta new to scripting in javascript how do you randomize the damage that a gun does like hhave the minimum damage set to 10 and the max to 20 would it be the same as changing crosshair sizes

  • Eye am the strongest!
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 571
    • View Profile
Re: randomizing weapon damage
« Reply #1 on: January 28, 2010, 09:41:51 AM »
Weapon damage is controlled through the projectile script, except for meele weapons.
If it's a ranged weapon, you could try setting the damage to a random number in the spawn function of the projectile.

Bored much?

Nightblaze

  • Sr. Member
  • ****
  • Posts: 309
  • ( ")✂ (^")
    • View Profile
Re: randomizing weapon damage
« Reply #2 on: January 28, 2010, 12:51:05 PM »
...randomize the damage that a gun does...  ...the same as changing crosshair sizes...


Do mean random damage? Or the further away the target is, the less damage the gun does?

Alexander Smith

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1003
  • Cold Fusion Games
    • AOL Instant Messenger - coldfusiongames
    • View Profile
    • Cold Fusion Games
    • Email
Re: randomizing weapon damage
« Reply #3 on: January 28, 2010, 01:49:33 PM »
He means a settable min and max where the game would just choose a number between that.

Look at the docs, and look for the Utility object section. There's a utility.random.getInteger you could use.

twproductions

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: randomizing weapon damage
« Reply #4 on: January 28, 2010, 06:27:05 PM »
ok i followed ure advice at least i think i did heres my code
Code: [Select]
if (proj.action.collision==true) {
getInteger(31,35);
}

i keep getting an error message saying it doesnt recognize the getinteger bit

`teh1

  • OOK Dev
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 531
  • Behold(Eventually): OOK
    • AOL Instant Messenger - flagoworld
    • View Profile
    • Spiral Nebula Development
    • Email
Re: randomizing weapon damage
« Reply #5 on: January 28, 2010, 06:32:13 PM »
No. Did you read the code he posted? You should take some basic javascript tutorials before you even begin this.

http://www.echoecho.com/javascript0.htm

Note that yes, this tutorial is for browser-based javascript, but it should teach you enough to transition over to Dim3's custom APIs.
~Ryan

http://wa.site40.net/ || Visit the apparel site!
http://www.facebook.com/group.php?gid=103158368628 || Join the group!
http://spiralnebuladev.com/ || Visit Spiral Nebula Development!
http://teh1ghool.blogspot.com/ || See my blog!

`teh1

  • OOK Dev
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 531
  • Behold(Eventually): OOK
    • AOL Instant Messenger - flagoworld
    • View Profile
    • Spiral Nebula Development
    • Email
Re: randomizing weapon damage
« Reply #6 on: January 28, 2010, 06:35:26 PM »
Alex. It wasn't in a code block. And even just using what he posted it won't work. You need to find out where in the script the damage is set and set it to that random integer. Also - Take the tutorial I linked you to FIRST.
~Ryan

http://wa.site40.net/ || Visit the apparel site!
http://www.facebook.com/group.php?gid=103158368628 || Join the group!
http://spiralnebuladev.com/ || Visit Spiral Nebula Development!
http://teh1ghool.blogspot.com/ || See my blog!

twproductions

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: randomizing weapon damage
« Reply #7 on: January 28, 2010, 07:25:16 PM »
ok then does this look good
Code: [Select]
proj.action.damage=16;
proj.action.damage=17;
result=proj.action.damage+proj.action.damage;
proj.action.collision=true;

`teh1

  • OOK Dev
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 531
  • Behold(Eventually): OOK
    • AOL Instant Messenger - flagoworld
    • View Profile
    • Spiral Nebula Development
    • Email
Re: randomizing weapon damage
« Reply #8 on: January 28, 2010, 07:55:59 PM »
That makes no sense. Again, read the tutorial and become pretty fluent in javascript first.
~Ryan

http://wa.site40.net/ || Visit the apparel site!
http://www.facebook.com/group.php?gid=103158368628 || Join the group!
http://spiralnebuladev.com/ || Visit Spiral Nebula Development!
http://teh1ghool.blogspot.com/ || See my blog!

  • Eye am the strongest!
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 571
    • View Profile
Re: randomizing weapon damage
« Reply #9 on: January 29, 2010, 02:22:08 AM »
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.

Code: [Select]
// ***********************************************************
//
// 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;
}
}

Bored much?

`teh1

  • OOK Dev
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 531
  • Behold(Eventually): OOK
    • AOL Instant Messenger - flagoworld
    • View Profile
    • Spiral Nebula Development
    • Email
Re: randomizing weapon damage
« Reply #10 on: January 29, 2010, 02:59:33 AM »
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.

Code: [Select]
// ***********************************************************
//
// 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;
}
}



I don't think you'll want to be creating a variable just so that yo can set the damage to that variable. It's slower to create extraneous variables. Set it directly to the random int.
~Ryan

http://wa.site40.net/ || Visit the apparel site!
http://www.facebook.com/group.php?gid=103158368628 || Join the group!
http://spiralnebuladev.com/ || Visit Spiral Nebula Development!
http://teh1ghool.blogspot.com/ || See my blog!

twproductions

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: randomizing weapon damage
« Reply #11 on: January 29, 2010, 12:48:23 PM »
ty to all who helped or attempted to help

.Minimum

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
Re: randomizing weapon damage
« Reply #12 on: February 05, 2010, 12:38:28 AM »
I have a similar problem that cannot be fixed by the way Bink put forward (Unless I'm doing it all wrong), and I thought it might be more appropriate to put it here than to make a whole new thread. So, how do I make random marks?
OK ODDITY

Jerion

  • Hero Member
  • *****
  • Posts: 674
  • El Duderino
    • AOL Instant Messenger - Zeoman1001
    • View Profile
    • Digital Musings
    • Email
Re: randomizing weapon damage
« Reply #13 on: February 05, 2010, 08:20:02 AM »
I have a similar problem that cannot be fixed by the way Bink put forward (Unless I'm doing it all wrong), and I thought it might be more appropriate to put it here than to make a whole new thread. So, how do I make random marks?


It's pretty straightforward to randomly select from a list of marks in an array. Just use utility.random.getInteger(min,max);