Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   variables and tokenize (https://forums.graalonline.com/forums/showthread.php?t=134265341)

Alpho 12-20-2011 11:12 PM

variables and tokenize
 
Hello, I have been tooling around with this for quite a while now, and I can't quite put my finger on how to do this correctly. I have a series of variables that look a little something like this:
PHP Code:

this.test_Yes 4;
this.test_Yea 4;
this.test_Lol 2;
this.test_Abc 3

I am trying to pull information out of the string. For instance; Lets say my account is labeled "Yes", and my buddies account is "Lol". I want to see if our accounts are existant in the variable strings, and set the number as a client flag in their attributes.

For example:
My account is Yes, so looking at the above script, I would get the number '4' added to my attributes.

How am I able to pull this information out of the variables?
I hope all of the above makes sence.

Thanks in advance,
Alpho.

fowlplay4 12-20-2011 11:13 PM

Based on your example:

temp.value = this.("test_" @ player.account);

Alpho 12-20-2011 11:22 PM

What about from this example:
PHP Code:

  this.acc_Graal756204 4

How would I check if someones account is after this.acc_ and if true, set something in their attrs to 4?

fowlplay4 12-20-2011 11:34 PM

Change temp.value to whatever clientr.flag_you_want_to_store_it_in

callimuc 12-20-2011 11:36 PM

Quote:

Originally Posted by Alpho (Post 1678828)
What about from this example:4
PHP Code:

  this.acc_Graal756204 4

How would I check if someones account is after this.acc_ and if true, set something in their attrs to 4?

Not sure (currently Trial again) but something like this could help:
PHP Code:

function onCreated() {
  
this.acc_Graal756204 4;
  
temp.check this.acc_.getvarnames();
  for (
temp.i=0temp.i<temp.check.size(); temp.i++) {
    if (
player.account in temp.check) {
      
player.attr[4] = this.acc_(@player.account);
      echo(
player.attr[4];
    }
  }



Alpho 12-20-2011 11:36 PM

Quote:

Originally Posted by fowlplay4 (Post 1678837)
Change temp.value to whatever clientr.flag_you_want_to_store_it_in



Ok, I tried the following:
PHP Code:

  this.acc_Graal756204 4;
  
clientr.stafflevel this.("acc_" player.account); 

results in nothing. Any ideas?

fowlplay4 12-20-2011 11:40 PM

Quote:

Originally Posted by Alpho (Post 1678840)
Any ideas?

What function are you doing this in?

Alpho 12-20-2011 11:41 PM

Tried what you said calli, sorry didn't work, tried a similar approach at it, same result:
PHP Code:

this.acc_Graal756204 4;
  
temp.check this.acc_.getvarnames(); 
  for (
temp.i=0temp.i<temp.check.size(); temp.i++) {
    if (
player.account in temp.check) { 
      echo(
this.acc_(@player.account)); 
    }
  } 


Alpho 12-20-2011 11:41 PM

Quote:

Originally Posted by fowlplay4 (Post 1678843)
What function are you doing this in?

Serverside, onCreated

fowlplay4 12-20-2011 11:45 PM

Quote:

Originally Posted by Alpho (Post 1678845)
Serverside, onCreated

That's because there's no 'player' object in onCreated in a Weapon or DB-NPC.

Alpho 12-20-2011 11:51 PM

Oh thanks, I see that now. This works:

PHP Code:

function onCreated() {
  
this.acc_Graal756204 4;
  
  echo(
this.("acc_Graal756204"));


how do you suppose I can get the 'player' object, 'in sight' ?



Edit: Got it to work
PHP Code:


function Set(pl) {
  
this.acc_Graal756204 4;
  echo(
this.("acc_"@pl));
}

function 
onActionServerSide() {
  if (
params[0] == "test") {
    
Set(params[1]);
  }
}

//#CLIENTSIDE
function onCreated() {
  
triggerserver("gui"name"test"player.account);



fowlplay4 12-20-2011 11:58 PM

Quote:

Originally Posted by Alpho (Post 1678849)
Oh thanks, I see that now. This works:

how do you suppose I can get the 'player' object, 'in sight' ?

If you're trying to set the value when the player logins you can do so in the onActionPlayerOnline function in Control-NPC or onPlayerLogin in other scripts.

If you want to 'find' the player object you can do like this:

findplayer("Graal756204").clientr.flag = this.acc_Graal756204;

or you can use with a statement:

PHP Code:

function onCreated() {
  
this.acc_Graal756204 4;
  
with (findplayer("Graal756204")) {
    
// You have to use thiso instead of just this because the 
    // with statement changes the scope to the player object.
    
clientr.flag thiso.("acc_" player.account);
  }



Tolnaftate2004 12-21-2011 12:12 AM

Quote:

Originally Posted by fowlplay4 (Post 1678850)
PHP Code:

    // You have to use thiso instead of just this because the 
    // with statement changes the scope to the player object. 


Not in this case.

Alpho 12-21-2011 01:51 AM

I got it all to work! Thanks for everyone's help.


All times are GMT +2. The time now is 12:39 AM.

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