Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Adding clientr variables via weapons (https://forums.graalonline.com/forums/showthread.php?t=134269619)

Struggler 10-14-2014 07:38 PM

Adding clientr variables via weapons
 
Hello, I was just wondering if maybe someone could help me, I seem to be having a lot of trouble adding a clientr variable to a player via the weapon he holds. Is there any way to accomplish this? So far I've tried clientr.[variablenamehere].add(0) but it thinks its an array so it automatically adds a comma after the number. I've also tried just clientr.[variablename] = 0 but it doesnt add the variable because it doesn't exist yet. Any help would be greatly appreciated :)

Note: Also tried clientr.[variablenamehere].add(0) and then using clientr.[variablenamehere] = 0 in the same script but it refuses to add it because clientr.[variablenamehere] = 0 seems to be faulty in some way.

Struggler 10-14-2014 07:49 PM

An example of the current script I'm referring to (weapon script)
Quote:

function onActionServerside(){
if (params[0] == "updatevars"){
clientr.treescut = 0;
}
}
//#CLIENTSIDE
function onCreated(){
if (!clientr.treescut){
triggerserver("gui",this.name,"updatevars");
}
}

Tim_Rocks 10-14-2014 07:56 PM

Hopefully you're doing this on serverside.

When you do player.clientr.whatever = null; it shouldn't appear in your players attributes unless the value is anything other than null. So if you were to add the following within any serverside function: player.clientr.whatever = "supercoolvar"; echo(player.clientr.whatever); I'd expect to see supercoolvar output on RC. The reason you're able to see an output for player.clientr.whatever.add(0); is because you're creating an array which adds another null value every time the function is called.

Actually scrach that, are you trying to verify a tree has been cut down before you can chop it?

Struggler 10-14-2014 07:59 PM

Ah so question: If I add a clientr variable they wont always appear in a player's script flags under attributes?

Because I tried echo, it echo'd the value correctly but its not displayed under script flags.

As of now I'm just trying to figure out how to get the clientr variables to work correctly so I can keep track of how many trees have been cut down.

callimuc 10-14-2014 08:06 PM

Quote:

Originally Posted by Struggler (Post 1732000)
Ah so question: If I add a clientr variable they wont always appear in a player's script flags under attributes?

Because I tried echo, it echo'd the value correctly but its not displayed under script flags.

like tim said, it wont display if it equals NULL or when it's blank. Try it with another number or string, like 1 or "hello".
Also make sure to use player.clientr.flag, not just clientr.flag

Struggler 10-14-2014 08:08 PM

Ah, now it shows up when I changed it to 1. So how would I set a clientr variable to the number 0 then? Or should I just get it to detect that there's none and have a default conditional to go to if that's the case?

As clarification I'm trying to get it to actively read the clientr variable so that the player can keep track of how many trees he's cut down. But when the clientr variable is set to 0, it can't effectively keep track of it. Are clientr variables 0 by default? Is 0 the equivelant of null?

callimuc 10-14-2014 08:13 PM

Quote:

Originally Posted by Struggler (Post 1732002)
Ah, now it shows up when I changed it to 1. So how would I set a clientr variable to the number 0 then? Or should I just get it to detect that there's none and have a default conditional to go to if that's the case?

You can always set it to 0, in the end when you want to display it, it will show 0 anyway. 0 is equal to NULL, you can also try echo(player.clientr.randomlettershere) without creating that flag in the first place, it will also return 0

Struggler 10-14-2014 08:14 PM

But I'm trying to get this script to display the clientr value in a say2, but when it's set to 0, it's blank.

Tim_Rocks 10-14-2014 08:16 PM

Quote:

Originally Posted by Struggler (Post 1732002)
Ah, now it shows up when I changed it to 1. So how would I set a clientr variable to the number 0 then? Or should I just get it to detect that there's none and have a default conditional to go to if that's the case?

Depends, I'm still trying to figure out what your script is supposed to accomplish.

PHP Code:

function onActionServerside(){
  if (
params[0] == "updatevars"){
    
player.clientr.treescut true;
    echo(
player.clientr.treescut);
  }
}

//#CLIENTSIDE
function onCreated(){
  if (
player.clientr.treescut == false) { //Your variable will have to be false to trigger serverside again
    
triggerserver("gui"this.name"updatevars");
  }



Struggler 10-14-2014 08:22 PM

Okay with the collection of yougize's help I have in fact solved the problem. The problem wasnt that the value wasnt being assigned, it's that I was assigned the variable a null value so it just wasnt being displayed. I have now added an if conditional to detect if the treescut variable is 0 and if so perform accordingly. Thank you both for your assistance :)


All times are GMT +2. The time now is 02:38 AM.

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