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 05-24-2010, 12:31 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Question about "autodetecting" variables.

okay, so i'm trying to set up my system to read a variable and use that variable to create the name of another variable to read from. say if i wanted a weapon to calculate damage from an unusual stat such as say, accuracy. i could just put something like damagebase=accuracy in the weapon file to make things easier.

in this example, we're just going to manually set the kind of damage the weapon would be using in client.weapon_damagebase.

with this line, i can get it to put together an existing variable name:
PHP Code:
this.damagebase "client.stats_" client.weapon_damagebase
so if i send this.damagebase through to the player's chat, they'll say "client.stats_accuracy"

now the actual problem is that although i've managed to make it put that together, i cant figure out how to tell it to read from that variable since my attempts have always made this.damagebase return "client.stats_accuracy". i think my problem is that it's treating what's stored, as a string, and not actually a variable. what would i use to tell it to read from the actual client.stats_accuracy variable in this manner?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #2  
Old 05-24-2010, 12:55 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
To create dynamic variables you have two options.

First (best):
PHP Code:
object.(@ "something")
(@ 
"object.something")
(@ 
this.damagebase
Second (don't use, please):
PHP Code:
makevar("object.var"
So if you were calculating a damage multiplier you would do
PHP Code:
function getPlayerDamageMultiplier() {
  return (@ 
this.damagebase);

__________________
Reply With Quote
  #3  
Old 05-24-2010, 03:41 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
I cant seem to get it to work. your way didnt seem to make this.damagebase equal anything but null no matter which way i tried it. so perhaps im doing it wrong. i also tried doing both:

PHP Code:
this.damagebase "client.stats_" client.weapon_damagebase;
makevar(this.damagebase);
player.chat this.damagebase
and

PHP Code:
this.damagebase "client.stats_" client.weapon_damagebase;
makevar("this.damagebase");
player.chat this.damagebase
to see if that would even work, but my char still said "client.stats_strength" instead of the actual value stored in client.stats_strength.

Also, why is your first example preferred over the second? Is it more versatile, or is it just outdated (i.e. gs1)?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #4  
Old 05-24-2010, 05:21 PM
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
Quote:
Originally Posted by Jiroxys7 View Post
...im doing it wrong....
PHP Code:
this.damagebase "client.stats_" client.weapon_damagebase;
player.chat makevar(this.damagebase); 
__________________
◕‿‿◕ · 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
  #5  
Old 05-24-2010, 05:31 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by cbk1994 View Post
Second (don't use, please):
PHP Code:
makevar("object.var"
Why not?
Reply With Quote
  #6  
Old 05-24-2010, 06:04 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Crow View Post
Why not?
Well you call a function and the other doesn't from what I understand, so it's just one of those unnoticeable differences.

Personally I used makevar at first but eventually migrated to the object.("var") way, it was a lot easier to work with after I got use to it.
__________________
Quote:
Reply With Quote
  #7  
Old 05-24-2010, 09:20 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
Quote:
Originally Posted by fowlplay4 View Post
Well you call a function and the other doesn't from what I understand, so it's just one of those unnoticeable differences.

Personally I used makevar at first but eventually migrated to the object.("var") way, it was a lot easier to work with after I got use to it.
Yeah, me too
__________________
Reply With Quote
  #8  
Old 05-24-2010, 10:03 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Crow View Post
Why not?
makeVar is disgusting and counter-intuitive in an object-oriented programming language.
__________________
Reply With Quote
  #9  
Old 05-25-2010, 03:38 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Quote:
Originally Posted by Tolnaftate2004 View Post
PHP Code:
this.damagebase "client.stats_" client.weapon_damagebase;
player.chat makevar(this.damagebase); 
okay, in my attributes, i have client.weapon_damagebase=strength
also, in my attributes, client.stats_strength currently equals 190

my script, of course contains
PHP Code:
this.damagebase "client.stats_" client.weapon_damagebase
using player.chat = makevar(this.damagebase); set my chat text to "client.weapon_damagebase" when its supposed to say "190". i also just tried using player.chat = (@ this. damagebase); and got the exact same result. all of this is being done clientside. but i dont think anything needs to go through the serverside, so i dont think that could be the problem. What else might I be doing wrong?

edit: hold on, it seems that someone broke my server and now nothing's updating >:0
__________________
MY POSTS ARE PRONE TO EDITS!

Last edited by Jiroxys7; 05-25-2010 at 04:15 AM..
Reply With Quote
  #10  
Old 05-25-2010, 04:59 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
try
PHP Code:
this.damagebase player.client.(@ "stats_" player.client.weapon_damagebase); 
I hope this just for displaying information in an interface or something that doesn't need to be secure...you shouldn't be using client.vars otherwise. If not, I can help you figure out a better way to do what it is you need to do.
__________________
Reply With Quote
  #11  
Old 05-25-2010, 05:29 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Quote:
Originally Posted by salesman View Post
try
PHP Code:
this.damagebase player.client.(@ "stats_" player.client.weapon_damagebase); 
I hope this just for displaying information in an interface or something that doesn't need to be secure...you shouldn't be using client.vars otherwise. If not, I can help you figure out a better way to do what it is you need to do.
I plan on changing that later. dont you calculate and set variables as .clientr serverside or something for that?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #12  
Old 05-25-2010, 05:49 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
clientr.vars can be read by both the client and server, but can only be altered on the serverside
__________________
Reply With Quote
  #13  
Old 05-25-2010, 06:00 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
so if i needed to send a variable over to serverside to be calculated for a clientr.var, would i send a temp.var or a this.var? or something else?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #14  
Old 05-25-2010, 07:19 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by Jiroxys7 View Post
so if i needed to send a variable over to serverside to be calculated for a clientr.var, would i send a temp.var or a this.var? or something else?
I'm not exactly the best teacher, so you probably want someone else to help you out, however I will try!

temp.variables are only accessible in the function where they are defined. For example,
PHP Code:
function someFunction() {
  
temp.foo 3.14159// define temp.foo in this function block
  
  
echo(temp.foo// echoes 3.14159

  
otherFunction(); // call a new function
}

function 
otherFunction() {
  echo(
temp.foo); // this will NOT echo anything, because temp.foo was not defined in this function
  
  // however, I can define an entirely new temp.foo, completely unrelated to the temp.foo in someFunction()
  
temp.foo "test";

Parameters passed to a function are also temp.vars and are only accessible within the function block.

this.variables on the other hand are assigned to the object in which they are defined (hence "this") and are accessible throughout the object

for example,
PHP Code:
function someFunction() {
  
this.foo "bar";
  
  echo(
this.foo); // echoes "bar"

  
otherFunction();
}

function 
otherFunction() {
  echo(
this.foo); // echoes "bar"

I can even access the variable from other objects as long as I have a reference to the object in which it was defined. Say this.foo was declared in a DBNPC called "MyNPC"...I can access the variable "foo" with the following statement from another NPC:
PHP Code:
// Another DB NPC

function inAnotherNPC() {
  echo(
MyNPC.foo); // echoes "bar"

It is important to note that a this.var defined on the serverside cannot be accessed on the clientside (or vice-versa). So how do you send data between the two? There are a few methods, but most notably, triggerServer() and triggerClient().

triggerServer() is called from the clientside and will invoke the event "onActionServerSide()" on the serverside. Alternatively, triggerClient() will invoke "onActionClientSide()" on the clientside.

Both require two parameters, and also allow an arbitrary (i think?) number of extra parameters.
  1. The first parameter will be the type of NPC you are triggering ("weapon", "gui", or "npc"). weapon and gui are interchangeable, and should be used for WNPCs, npc should be used for DB NPCs.
  2. The second is the name of the NPC

for example, I want to call a function in a weapon NPC on the serverside from the clientside of the same weapon:
PHP Code:
// invoked whenever triggerServer() is used on this weapon
function onActionServerSide(cmd) {
  
// "cmd" is a parameter that I specified in order to ensure that the trigger is the one I want
  
if (temp.cmd == "test") { // I sent "test" as a parameter from the clientside
    
myServersideFunction();
  }
}

//#CLIENTSIDE

function someFunction() {
  
triggerServer("weapon"this.name"test");


So to answer your question, you can send any type of variable you want as a parameter via triggerServer(). You can then assign the parameter on the serverside to a clientr.var, this.var, or pass it to another function...whatever you want. If this is confusing just ignore everything I said and wait for someone else to help you
__________________
Reply With Quote
  #15  
Old 05-25-2010, 07:50 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
I believe im fairly familiar with using the serverside <=> clientside stuff. didnt know the difference between temp.var and this.var though =3

so if i want to create an important clientr.var, i should do something like this?:

example:

PHP Code:
function onActionServerSide(cmd) {
  if (
temp.cmd == "calc_math") {
    
doMakeMathVar_S();
  }
}

function 
doMakeMathVar_S(){
   
clientr.num this.num1 this.num2;
}

//#CLIENTSIDE

function doMakeMathVar_C() {
  
this.num1 1;
  
this.num2 2;
  
triggerServer("weapon"this.name"calc_math"this.num1this.num2);

clientr.num should equal 3.

now, I'm wondering though, are people able to hack and edit this.num1 and this.num2 to change the outcome of clientr.num? or is it just harder to hack compared to client.vars?
__________________
MY POSTS ARE PRONE TO EDITS!
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 04:56 PM.


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