Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   gunscript not doing dmg to people (https://forums.graalonline.com/forums/showthread.php?t=134257118)

GULTHEX 11-29-2009 08:08 PM

gunscript not doing dmg to people
 
NPC Code:
//#CLIENTSIDE
function onCreated() {
this.firerate = .2;
}

function onWeaponFired() {
while (keydown(4)) {
FireGun();
sleep(this.firerate);
}
}

function FireGun() {
setani("millenium_scar-fire", "");

this.spread=.053;
this.speed=5;
this.reload=50;
this.load=50;

temp.angl = getangle(vecx(player.dir), vecy(player.dir))+random(this.spread*-1,this.spread);
shoot(player.x + 0.5 + vecx(player.dir), player.y + vecy(player.dir), player.z, temp.angl, 0, 0, "mil_bullets", player.dir);
}
function onActionProjectile()
{
if (clientr.hp>=0) {
setani hurt,;
}
}




the problem is that when i shoot people they set ani hurt

but for some people nothing happens


ps

sorry about my gs1 habbits :(

im doing a little bit better with gs2 tho :)

Programmer 11-29-2009 08:12 PM

The error is that you don't have any code to decrease the player's health in the first place! :P

Try adding clientr.hp -= YOUR_DAMAGE_HERE; after setani hurt,; (which should be setani("hurt", null);) and see if it works.

fowlplay4 11-29-2009 08:14 PM

Whoever has that gun will be able to get hit, everyone who doesn't won't.

You need to take the actionProjectile code out of the gun and put it in it's own script called, -System/Damage or something and then make sure everyone has it.

Your gun script:

PHP Code:

//#CLIENTSIDE

function onCreated() {
  
this.firerate .2;
}

function 
onWeaponFired() {
  while (
keydown(4)) {
    
FireGun();
    
sleep(this.firerate);
  }
}

function 
FireGun() {
  
setani("millenium_scar-fire""");
  
this.spread=.053;
  
this.speed=5;
  
this.reload=50;
  
this.load=50;
  
temp.angl getangle(vecx(player.dir), vecy(player.dir))+random(this.spread*-1,this.spread);
  
shoot(player.0.5 vecx(player.dir), player.vecy(player.dir), player.ztemp.angl00"mil_bullets"player.dir);


-System/Damage:

PHP Code:

//#CLIENTSIDE
function onActionProjectile() {
  if (
clientr.hp>=0) {
    
setani("hurt""");
  } 



cbk1994 11-29-2009 08:26 PM

I've already explained in other threads that you need to place the damage into another weapon, and even given you the code for the HP system:

Quote:

Originally Posted by cbk1994 (Post 1541092)
PHP Code:

function onActionServerSide(cmddamage) {
  if (
cmd == "hit") {
    
this.hitPlayer(damage);
  }
}

function 
hitPlayer(damage) {
  
player.clientr.hp max (0player.clientr.hp damage); // max() chooses the largest of the two values
  
  
if (player.clientr.hp <= 0) {
    
this.playerDead();
  } else {
    
player.setAni("hurt"NULL);
  }
}

function 
playerDead() {
  
player.setAni("dead"NULL);
  
player.setlevel2("onlinestartlocal.nw"2155);
  
// now you'll need eventually to heal them
  
}
//#CLIENTSIDE
function onActionProjectile(damage) {
  
triggerServer("gui"this.name"hit"damage);



Every player has to have the system weapon. The way it works is when a player is hit with a bullet, it calls the "onActionProjectile" event in every weapon. If a weapon has the event "defined", then it will be executed. If they don't have your gun script, which is where you mistakenly put the HP checks, then it won't be called.

Take your onActionProjectile code, place it in to a weapon like "-Health", and add a line of code in the Control-NPC to add it to players on login.

EDIT: Jerret beat me to it :(


All times are GMT +2. The time now is 07:36 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.