Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   GScript2 Questions (https://forums.graalonline.com/forums/showthread.php?t=57608)

Evil_Trunks 02-12-2005 06:56 AM

GScript2 Questions
 
1. I can't do this for some reason
PHP Code:

colors player.colors

both are arrays
i can do this, however
PHP Code:

this.array = colors

the array of NPC colors is copied to this.array

2. hasweapon, it does not work for me (using old gscript serverside)
and i can't figure out what the correct substitution is for this

3. addstring, I can't get this to work with gscript2
PHP Code:

addstring(this.list,"test");
message(this.list); 

the message shows 0

4. could someone explain getstring()?
edit: nevermind this one

ApothiX 02-12-2005 09:39 AM

Quote:

Originally Posted by Evil_Trunks
1. I can't do this for some reason
PHP Code:

colors player.colors


perhaps something like:
NPC Code:
for(i=0;i<player.colors.size();i++) {
colors[i] = player.colors[i];
}


or something might work


Quote:

Originally Posted by Evil_Trunks
3. addstring, I can't get this to work with gscript2
PHP Code:

addstring(this.list,"test");
message(this.list); 

the message shows 0

the correct syntax is:
NPC Code:
this.list.add("test");
message(this.list);


Lance 02-12-2005 10:09 AM

Quote:

Originally Posted by ApothiX
perhaps something like:
NPC Code:
for(i=0;i<player.colors.size();i++) {
colors[i] = player.colors[i];
}


or something might work

You don't need to calculate the size each pass through the loop, you know.

Arkan1k 02-12-2005 10:20 AM

You could probably just do this:
NPC Code:
i = 0;
for (colour: player.colors) {
colours[i] = colour;
i++;
}


ApothiX 02-12-2005 07:09 PM

Quote:

Originally Posted by Lance
You don't need to calculate the size each pass through the loop, you know.

It was an example, I wasn't going for efficiency as much as method.

ChibiChibiLuc 02-13-2005 04:31 AM

Quote:

Originally Posted by Evil_Trunks
2. hasweapon, it does not work for me (using old gscript serverside) and i can't figure out what the correct substitution is for this

There's no substitute for hasweapon. =(

Arkan1k 02-13-2005 05:39 AM

findweapon(str) - returns object

I'd presume you'd do something like:
NPC Code:
if (findweapon(weaponname) == true) {
doStuff();
}



I haven't had a play with it, but I'd say from the name of the command it would probably be the substitute, or close to, for hasweapon(str);

Evil_Trunks 02-13-2005 05:55 AM

Quote:

Originally Posted by Arkan1k
findweapon(str) - returns object

I'd presume you'd do something like:
NPC Code:
if (findweapon(weaponname) == true) {
doStuff();
}



I haven't had a play with it, but I'd say from the name of the command it would probably be the substitute, or close to, for hasweapon(str);

That gives an object link to the weapon, but I think that you can get a link to a weapon you do not possess?


also, i am trying to do something like this:
something = "text" @ var;
but if var is 1, i dont want it to set to text1, i want it to give me the value of text1

if someone could help me out with that i'd appreciate it x.x

Tolnaftate2004 02-13-2005 06:08 AM

I don't have gscript2 on the server I work on, but I would try:

PHP Code:

if (findweapon(namein weapons){
  
// blah



ApothiX 02-13-2005 06:11 AM

If you can't find a substitute for hasweapon(), you could always script your own.

This should work:
PHP Code:

function PlayerHasWeapon(weaponname) {
  for(
wweapons) {
    if(
w.name == weaponname) {
      return 
true;
    }
  }

  return 
false;


That might not be the best way to do it, but it will work. (I'm not sure, if you can use something like weapons.name.index(weaponname) or not)

Malinko 02-13-2005 03:50 PM

Quote:

Originally Posted by ApothiX
It was an example, I wasn't going for efficiency as much as method.

I would figure you want to show someone an example in the most efficient way? You know, so they get the point in the better way.

ApothiX 02-13-2005 08:56 PM

Quote:

Originally Posted by Malinko
I would figure you want to show someone an example in the most efficient way? You know, so they get the point in the better way.

I'm not here to write the best code for people. I gave them a method of doing it, if they want to improve it and make it more efficient, that's up to them.

Inverness 02-13-2005 10:03 PM

Am I correct in saying that instead of using something like:
NPC Code:
player.chat = "Account #s(this.string1) was kicked";


I would use:
NPC Code:
player.chat = "Account" @ this.string1 @ "was kicked";


I'm confused about that, because I want a deffinate way of identifying what the stringname is from the rest of the words.

I hope this makes sense.

Evil_Trunks 02-13-2005 10:17 PM

Quote:

Originally Posted by Inverness
Am I correct in saying that instead of using something like:
NPC Code:
player.chat = "Account #s(this.string1) was kicked";


I would use:
NPC Code:
player.chat = "Account" @ this.string1 @ "was kicked";


I'm confused about that, because I want a deffinate way of identifying what the stringname is from the rest of the words.

I hope this makes sense.

you're definitely right
message codes are outdated and shouldnt be used anymore

although you forgot the space
NPC Code:
player.chat = "Account " @ this.string1 @ " was kicked";


Inverness 02-13-2005 10:40 PM

Hmm, So I would do:
NPC Code:
player.chat = "Account " @ this.string1 @ " was kicked";


instead of:
NPC Code:
player.chat = "Account "@this.string1@" was kicked";



because it appears to have to many spaces in the first one, why is that? >.<

falco10291029 02-13-2005 11:32 PM

Hey could someone tell em the gs2 version of strcontains?

Skyld 02-13-2005 11:40 PM

contains(str as string,partstr as string) which returns a true/false

falco10291029 02-13-2005 11:53 PM

alright, and (I ahve one other question (for now).

whenever I ahve something like:
NPC Code:

this.image=tokens[2];


it gets an error in the rc saying "error: unexpected token: ; at line 5: this.image=tokens[2];"

how do i fix that?

Skyld 02-14-2005 12:46 AM

Check the lines before it for missing ;'s, or brackets, etc.

falco10291029 02-14-2005 02:08 AM

alright after some tweaking I ended up with the error:
"unexpected token: at line 12: for (pl: allplayerscount) {"

and it doesnt say what shouldnt be there :whatever:

Tolnaftate2004 02-14-2005 02:27 AM

PHP Code:

for (plallplayers){
  
// stuff



ApothiX 02-14-2005 02:28 AM

Quote:

Originally Posted by falco10291029
alright after some tweaking I ended up with the error:
"unexpected token: at line 12: for (pl: allplayerscount) {"

and it doesnt say what shouldnt be there :whatever:

allplayerscount is a variable, not an array, the statement you are looking for is:
NPC Code:
for(pl: allplayers) {



[edit] bastard pfa beat me to it >:P [/edit]

falco10291029 02-14-2005 02:30 AM

ok, got it, sorry

EDIT: After changing that, i still get the same error

ApothiX 02-14-2005 03:58 AM

Quote:

Originally Posted by falco10291029
ok, got it, sorry

EDIT: After changing that, i still get the same error

Show the whole chunk of code that's before and after that?

falco10291029 02-14-2005 10:16 PM

Well since I haven't a clue what's wrong, here's the whole serverside script:

NPC Code:

if (actionserverside) {
tokens=params[0].tokenize;;
if (!params[1].starts("*")&&!strcontains(#p(1),"staff")&&!params[1].starts("subclass/")) {
putnpc2 tokens[0],tokens[1],{
this.image=tokens[2];
this.player=tokens[3];
this.class=tokens[4];
this.weapon=tokens[5];
setimg("block.png");
chat=this.weapon;
if (this.image.length()>=2) setimg(this.image);
for (pl: allplayers){
if (pl.account==this.player) {
removeweapon #s(this.weapon);
insertstring client.messages,0,you dropped a #s(this.weapon);
}
}
}
function onPlayerTouchsMe() {
addweapon(this.weapon);
destroy;
}
};



You'll notice that for once I styled my script ;)

NOte: It isn't completely GS2 yet, I figure it best to finish that after the errors are gone, and they shouldn't affect the rest of the code.

Evil_Trunks 02-14-2005 10:25 PM

NPC Code:
tokens=params[0].tokenize;;


i think this is the problem

(oh no I broke tree structure)

ApothiX 02-14-2005 10:32 PM

Quote:

Originally Posted by falco10291029
NPC Code:
tokens=params[0].tokenize;;


tokenize is a function, so it needs parenthesis after it, and also, why is there two semi-colons?

falco10291029 02-14-2005 11:07 PM

The semicolons...well must have been a typo, not that it really matter sthough

Skyld 02-15-2005 12:21 AM

tokens = params[0].tokenize();

Like Okiesmokie said.

ApothiX 02-15-2005 12:31 AM

Quote:

Originally Posted by falco10291029
The semicolons...well must have been a typo, not that it really matter sthough

Umm, you were getting a syntax error, no?
Two semi-colons is a syntax error ;)

falco10291029 02-15-2005 12:33 AM

Well i changed it and it didnt fix it

Admins 02-16-2005 09:31 PM

Ah thats a pretty heavy mix of old and new scripting which doesn't really work they way you did. Old functions and commands still expect the old syntax, and vice versa, e.g. it must be strcontains(#p(1),staff) or contains(#p(1),"staff") or contains(params[1],"staff")

falco10291029 02-16-2005 10:35 PM

Here I converted the whole thing to GS2 (serverside of course), it gives me the error still, heree's what it looks like (since I cant edit my old 1 for some reason):
NPC Code:

if (actionserverside) {
tokens=params[0].tokenize();
if (!params[1].starts("*")&&!contains(params[1],"staff")&&!params[1].starts("subclass/")) {
putnpc2 tokens[0],tokens[1],{
this.image=tokens[2];
this.player=tokens[3];
this.class=tokens[4];
this.weapon=tokens[5];
setimg("block.png");
chat=this.weapon;
if (this.image.length()>=2) setimg(this.image);
for (pl: allplayers) {
if (pl.account==this.player) {
removeweapon(this.weapon);
insertstring(client.messages,0,"you dropped a" @this.weapon);
}
}
}

function onPlayerTouchsMe() {
addweapon(this.weapon);
destroy;
}
};


Evil_Trunks 02-16-2005 11:27 PM

Quote:

Originally Posted by falco10291029
Here I converted the whole thing to GS2 (serverside of course),

NPC Code:
if (actionserverside) {


NPC Code:
putnpc2 tokens[0],tokens[1],{



also this is wrong:
NPC Code:
          removeweapon(this.weapon);


i think you need to use with() (don't think you can use objects with this command)
NPC Code:
      insertstring(client.messages,0,"you dropped a" @this.weapon);


this is bad too, you should use obj.insert(), and make sure this is in a with() as well, or use the player object

falco10291029 02-17-2005 01:34 AM

The fact that it's usiong the for each replaces with. For the actionserverside I was told that that's what you used, is it function onActionServerSide() if not? As for the others I'll fix them.

Doahh_p2p 02-17-2005 04:23 PM

Quote:

Originally Posted by falco10291029
The fact that it's usiong the for each replaces with. For the actionserverside I was told that that's what you used, is it function onActionServerSide() if not? As for the others I'll fix them.

Yes it is onActionServerside()

and at the end of the script...
PHP Code:

}; 

That should be a syntax error also

Ajira 02-17-2005 10:13 PM

Quote:

Originally Posted by Doahh_p2p
That should be a syntax error also

If you would have read it properly you would have noticed that that is the end of the putnpc2 block.

falco10291029 02-17-2005 10:14 PM

Alright fixed, now to attempt to debug my 5 other rc scripts, and try to get a clue as to what's wrong with the 500 levels npcs.....:whatever:

Doahh_p2p 02-20-2005 04:22 AM

Quote:

Originally Posted by Ajira
If you would have read it properly you would have noticed that that is the end of the putnpc2 block.

Whoops my bad


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

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