Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   'No ammo' Problem ! (https://forums.graalonline.com/forums/showthread.php?t=134265325)

Trakan 12-19-2011 05:59 AM

'No ammo' Problem !
 
Okay, hello everyone. I work on a gun script for my server but the problem is with the ammunitions :(
It say "No ammo" !
PHP Code:

//#CLIENTSIDE
function onPlayerChats() {
if (
player.chat "/ammo"){
  
clientr.ammo += 10;
  
clientr.capacityammo 5;
  
clientr.maxcapacityammmo 5;
  
setplayerprop #P2,holst_usp45.png;
  
replaceani walk,holst_gunwalk;
  
replaceani idle,holst_gunidle;
  
setplayerprop #c,Ammo added;
}
}
function 
onWeaponFired() {
  if (
clientr.ammo && clientr.capacityammo != 0) {
  
shoot(player.vecx(player.dir), player.vecy(player.dir), player.z, (playerdir 1) * pi 2NULLNULL"holst_bullet"NULL);
  
setani("holst_gunfire"NULL);
  
clientr.ammo -= 1;
  
clientr.capacityammo -= 5;
  
freezeplayer(0.75);
} else {
setplayerprop #c,No ammo!;
}
}
function 
onActionProjectile() {
  
player.hearts -= 6;
}
//#CLIENTSIDE
function onKeyPressedcodekey )
{
  if ( 
key == "e" || key == "E" )
  {
setani("holst_gunreload"NULL);



Tolnaftate2004 12-19-2011 06:29 AM

  1. You can't modify clientr variables on the client-side. You can perform tests with client variables, but for security reasons, you will want to use clientr variables, which means you will have to modify them on the server-side. If you don't know what I mean, I'm sure someone will post a link here for you. Otherwise, look into triggeraction, triggerclient, and triggerserver if you're not already familiar.
  2. Because clientr.ammo is unchanged, it is 0. Then, when you check if clientr.ammo < 0 (which, I am assuming should in fact be '>'), that test fails.
  3. You are mixing GS1 and GS2, which is bad form.

    To set the player's chat, use player.chat = "foo".
    To set the player's attributes (like #P2), use player.attr[2] = "bar".
    To replace a GANI, use replaceani("baz","qux").
  4. Use = as assignment only and use == as comparison only (see the 3rd line in your code). The engine will fix this for you, but it is bad practice.
  5. You will only need one //#CLIENTSIDE.

Gunderak 12-19-2011 11:23 AM

Use this serverside to modify a clientr var.
PHP Code:

function onActionServerSide(){
  if(
params[0] == "ammo"){
    
clientr.whatever 100;
  }


Then on the clientside to trigger it.
PHP Code:

triggerserver("weapon"this.name"ammo"); 

Also as I have learnt, style you're code.
Google JavaScript beautifier and run you're code through it.

Trakan 12-19-2011 03:59 PM

Quote:

Originally Posted by Tolnaftate2004 (Post 1678589)
  1. You can't modify clientr variables on the client-side. You can perform tests with client variables, but for security reasons, you will want to use clientr variables, which means you will have to modify them on the server-side. If you don't know what I mean, I'm sure someone will post a link here for you. Otherwise, look into triggeraction, triggerclient, and triggerserver if you're not already familiar.
  2. Because clientr.ammo is unchanged, it is 0. Then, when you check if clientr.ammo < 0 (which, I am assuming should in fact be '>'), that test fails.
  3. You are mixing GS1 and GS2, which is bad form.

    To set the player's chat, use player.chat = "foo".
    To set the player's attributes (like #P2), use player.attr[2] = "bar".
    To replace a GANI, use replaceani("baz","qux").
  4. Use = as assignment only and use == as comparison only (see the 3rd line in your code). The engine will fix this for you, but it is bad practice.
  5. You will only need one //#CLIENTSIDE.

Done, except first step.
Now i have that :
PHP Code:

//#CLIENTSIDE
function onPlayerChats() {
if (
player.chat == "/ammo"){
  
clientr.ammo += 10;
  
clientr.capacityammo 5;
  
clientr.maxcapacityammmo 5;
  
setplayerprop #P2,holst_usp45.png;
  
replaceani ("walk","holst_gunwalk");
  
replaceani ("idle","holst_gunidle");
  
setplayerprop #c,Ammo added;
}
}
function 
onWeaponFired() {
  if (
clientr.ammo && clientr.capacityammo != 0) {
  
shoot(player.vecx(player.dir), player.vecy(player.dir), player.z, (playerdir 1) * pi 2NULLNULL"holst_bullet"NULL);
  
setani("holst_gunfire"NULL);
  
clientr.ammo -= 1;
  
clientr.capacityammo -= 5;
  
freezeplayer(0.75);
} else {
player.chat "No Ammo!";
}
}
if (
clientr.ammo == 0) {
player.chat "No Ammo!";
}
function 
onActionProjectile() {
  
player.hearts -= 6;
}
function 
onKeyPressedcodekey )
{
  if ( 
key == "e" || key == "E" )
  {
setani("holst_gunreload"NULL);
}


And Gunderak, where i add this code?

Gunderak 12-19-2011 04:50 PM

I have tried to fix up you're script.
Try this out.
PHP Code:

function onActionServerSide() {
  if (
params[0] == "deductammo") {
    
clientr.ammo -= 1;
  }
  if (
params[0] == "add") {
    
clientr.ammo 10;
    
player.attr[15] = "holst_usp45.png";
  }
}

function 
onActionProjectile() {
  
player.hearts -= 6;
}
//#CLIENTSIDE 

function onPlayerChats() {
  if (
player.chat == "/ammo") {
    
triggerserver("weapon"this.name"add");
    
replaceani("walk""holst_gunwalk");
    
replaceani("idle""holst_gunidle");
    
player.chat == "Ammo Added!";
  }
}

function 
onWeaponFired() {
  if (
clientr.ammo 0) {
    
shoot(player.vecx(player.dir), player.vecy(player.dir), player.z, (playerdir 1) * pi 2NULLNULL"holst_bullet"NULL);
    
setani("holst_gunfire"NULL);
    
triggerserver("weapon"this.name"deductammo");
    
freezeplayer(0.75);
  } else {
    
player.chat "No Ammo!";
  }
}

function 
onKeyPressed(codekey) {
  if (
key == "e") {
    
setani("holst_gunreload"NULL);
    
triggerserver("weapon"this.name"reload");
  }


Also why was there capacityammo, maxcapacityammo and ammo.
You only really need two..
clip and ammo, but for this script you only need ammo.

callimuc 12-19-2011 06:08 PM

Quote:

Originally Posted by Gunderak (Post 1678622)
PHP Code:

function onActionProjectile() {
  
player.hearts -= 6;



Not sure, but for checking the onActionProjectile() on the serverside, isn´t it onActionProjecttileS() or something like that?

Trakan 12-19-2011 06:40 PM

Quote:

Originally Posted by Gunderak (Post 1678622)
I have tried to fix up you're script.
Try this out.
PHP Code:

function onActionServerSide() {
  if (
params[0] == "deductammo") {
    
clientr.ammo -= 1;
  }
  if (
params[0] == "add") {
    
clientr.ammo 10;
    
player.attr[15] = "holst_usp45.png";
  }
}

function 
onActionProjectile() {
  
player.hearts -= 6;
}
//#CLIENTSIDE 

function onPlayerChats() {
  if (
player.chat == "/ammo") {
    
triggerserver("weapon"this.name"add");
    
replaceani("walk""holst_gunwalk");
    
replaceani("idle""holst_gunidle");
    
player.chat == "Ammo Added!";
  }
}

function 
onWeaponFired() {
  if (
clientr.ammo 0) {
    
shoot(player.vecx(player.dir), player.vecy(player.dir), player.z, (playerdir 1) * pi 2NULLNULL"holst_bullet"NULL);
    
setani("holst_gunfire"NULL);
    
triggerserver("weapon"this.name"deductammo");
    
freezeplayer(0.75);
  } else {
    
player.chat "No Ammo!";
  }
}

function 
onKeyPressed(codekey) {
  if (
key == "e") {
    
setani("holst_gunreload"NULL);
    
triggerserver("weapon"this.name"reload");
  }


Also why was there capacityammo, maxcapacityammo and ammo.
You only really need two..
clip and ammo, but for this script you only need ammo.

This work thanks :).
I would put a limit-Standing for the charger. When the player shoots 5 balls, it must charge to fulfill its charger.
How can I do it?

callimuc 12-19-2011 08:58 PM

Quote:

Originally Posted by Trakan (Post 1678631)
This work thanks :).
I would put a limit-Standing for the charger. When the player shoots 5 balls, it must charge to fulfill its charger.
How can I do it?

You can simply add something like (not safe):

PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  if (
clientr.ammo && this.shootedtimes 5) {
    
shoot(player.vecx(player.dir), player.vecy(player.dir), player.z, (playerdir 1) * pi 2NULLNULL"holst_bullet"NULL);
    
setani("holst_gunfire"NULL);
    
triggerserver("weapon"this.name"deductammo");
    
this.shootedtimes ++; //increase the times the player fired the weapon
    
freezeplayer(0.75);
  }
  else {
    
player.chat "No Ammo!";
    
this.shootedtimes 0//no ammo or player fired the weapon 5 times? Well than the counter goes back to 0
    
setani("reload"NULL);
  }


or safe (just an example)

PHP Code:

function onActionServerSide() {
  if (
params[0] == "shootplus") {
    if (
clientr.firedtimes 5) { //just an additional check (needed?)
      
clientr.firedtimes ++; //increase the times the player fired the weapon by 1
      
clientr.ammo --; //decrease the ammo by 1
    
}
  }
  if (
params[0] == "shootminus") {
    
clientr.firedtimes 0//reset the shooting times
  
}
}

//#CLIENTSIDE
function onWeaponFired() {
  if (
clientr.ammo && clientr.firedtimes 5) {
    
player.chat "PENG!";
    
triggerserver("weapon"this.name"shootplus");
    
freezeplayer(0.75);
  }
  else {
    
player.chat "No peng :( let´s reload";
    
triggerserver("weapon"this.name"shootminus");
  }



Just something quick bumped

Tricxta 12-20-2011 03:28 AM

Quote:

Originally Posted by Gunderak (Post 1678622)
I have tried to fix up you're script....
Also why was there capacityammo, maxcapacityammo and ammo.
You only really need two..
clip and ammo, but for this script you only need ammo.

If you're going to fix his script how's he ever going to learn? If it's browny points you're after you'd do better to explain to him the steps taken to fix the script.

I would recite the give a guy a piece of bread and he'll live a day thing but you already get the point ;)

Gunderak 12-20-2011 06:23 AM

I wasn't after brownie points.
I think the best way to learn is by studying other scripts and trial and error.
That is why I fixed it up a bit.

Also, yes Callimuc I think it's onActionProjectiles(){
I wasnt paying enough attention.


All times are GMT +2. The time now is 05:22 PM.

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