Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-19-2011, 05:59 AM
Trakan Trakan is offline
It's all about cats!
Trakan's Avatar
Join Date: Sep 2010
Location: France
Posts: 64
Trakan is an unknown quantity at this point
'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);

Reply With Quote
  #2  
Old 12-19-2011, 06:29 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
  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.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #3  
Old 12-19-2011, 11:23 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #4  
Old 12-19-2011, 03:59 PM
Trakan Trakan is offline
It's all about cats!
Trakan's Avatar
Join Date: Sep 2010
Location: France
Posts: 64
Trakan is an unknown quantity at this point
Quote:
Originally Posted by Tolnaftate2004 View Post
  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?
Reply With Quote
  #5  
Old 12-19-2011, 04:50 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #6  
Old 12-19-2011, 06:08 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by Gunderak View Post
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?
__________________
MEEP!
Reply With Quote
  #7  
Old 12-19-2011, 06:40 PM
Trakan Trakan is offline
It's all about cats!
Trakan's Avatar
Join Date: Sep 2010
Location: France
Posts: 64
Trakan is an unknown quantity at this point
Quote:
Originally Posted by Gunderak View Post
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?
Reply With Quote
  #8  
Old 12-19-2011, 08:58 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by Trakan View Post
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
__________________
MEEP!
Reply With Quote
  #9  
Old 12-20-2011, 03:28 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
Quote:
Originally Posted by Gunderak View Post
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
Reply With Quote
  #10  
Old 12-20-2011, 06:23 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:25 PM.


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