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 02-12-2005, 06:56 AM
Evil_Trunks Evil_Trunks is offline
Evil
Evil_Trunks's Avatar
Join Date: Dec 2004
Posts: 391
Evil_Trunks is on a distinguished road
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
__________________


Last edited by Evil_Trunks; 02-12-2005 at 06:43 PM..
Reply With Quote
  #2  
Old 02-12-2005, 09:39 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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);

__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #3  
Old 02-12-2005, 10:09 AM
Lance Lance is offline
dark overlord
Lance's Avatar
Join Date: Sep 2003
Location: Space Jam Mountain
Posts: 5,072
Lance is on a distinguished road
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.
Reply With Quote
  #4  
Old 02-12-2005, 10:20 AM
Arkan1k Arkan1k is offline
Delph
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 35
Arkan1k is on a distinguished road
Send a message via AIM to Arkan1k Send a message via MSN to Arkan1k
You could probably just do this:
NPC Code:
i = 0;
for (colour: player.colors) {
colours[i] = colour;
i++;
}

__________________
[ Delph ]
Reply With Quote
  #5  
Old 02-12-2005, 07:09 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #6  
Old 02-13-2005, 04:31 AM
ChibiChibiLuc ChibiChibiLuc is offline
Cookie Monster. :3
Join Date: Jan 2005
Location: Nova Scotia, Canada
Posts: 111
ChibiChibiLuc is on a distinguished road
Send a message via AIM to ChibiChibiLuc Send a message via MSN to ChibiChibiLuc
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. =(
Reply With Quote
  #7  
Old 02-13-2005, 05:39 AM
Arkan1k Arkan1k is offline
Delph
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 35
Arkan1k is on a distinguished road
Send a message via AIM to Arkan1k Send a message via MSN to 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);
__________________
[ Delph ]
Reply With Quote
  #8  
Old 02-13-2005, 05:55 AM
Evil_Trunks Evil_Trunks is offline
Evil
Evil_Trunks's Avatar
Join Date: Dec 2004
Posts: 391
Evil_Trunks is on a distinguished road
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
__________________


Last edited by Evil_Trunks; 02-13-2005 at 10:04 AM..
Reply With Quote
  #9  
Old 02-13-2005, 06:08 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
I don't have gscript2 on the server I work on, but I would try:

PHP Code:
if (findweapon(namein weapons){
  
// blah

Reply With Quote
  #10  
Old 02-13-2005, 06:11 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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)
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #11  
Old 02-13-2005, 03:50 PM
Malinko Malinko is offline
Unholy Nation
Join Date: Mar 2004
Location: Massachusetts, U.S.A.
Posts: 1,782
Malinko is on a distinguished road
Send a message via AIM to Malinko
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.
Reply With Quote
  #12  
Old 02-13-2005, 08:56 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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.
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #13  
Old 02-13-2005, 10:03 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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.
__________________
Reply With Quote
  #14  
Old 02-13-2005, 10:17 PM
Evil_Trunks Evil_Trunks is offline
Evil
Evil_Trunks's Avatar
Join Date: Dec 2004
Posts: 391
Evil_Trunks is on a distinguished road
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";

__________________

Reply With Quote
  #15  
Old 02-13-2005, 10:40 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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? >.<
__________________
Reply With Quote
  #16  
Old 02-13-2005, 11:32 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Hey could someone tell em the gs2 version of strcontains?
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #17  
Old 02-13-2005, 11:40 PM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
contains(str as string,partstr as string) which returns a true/false
__________________
Skyld
Reply With Quote
  #18  
Old 02-13-2005, 11:53 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
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?
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #19  
Old 02-14-2005, 12:46 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Check the lines before it for missing ;'s, or brackets, etc.
__________________
Skyld
Reply With Quote
  #20  
Old 02-14-2005, 02:08 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
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
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #21  
Old 02-14-2005, 02:27 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
PHP Code:
for (plallplayers){
  
// stuff

Reply With Quote
  #22  
Old 02-14-2005, 02:28 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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
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]
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #23  
Old 02-14-2005, 02:30 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
ok, got it, sorry

EDIT: After changing that, i still get the same error
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #24  
Old 02-14-2005, 03:58 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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?
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #25  
Old 02-14-2005, 10:16 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
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.
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #26  
Old 02-14-2005, 10:25 PM
Evil_Trunks Evil_Trunks is offline
Evil
Evil_Trunks's Avatar
Join Date: Dec 2004
Posts: 391
Evil_Trunks is on a distinguished road
NPC Code:
tokens=params[0].tokenize;;


i think this is the problem

(oh no I broke tree structure)
__________________

Reply With Quote
  #27  
Old 02-14-2005, 10:32 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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?
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #28  
Old 02-14-2005, 11:07 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
The semicolons...well must have been a typo, not that it really matter sthough
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #29  
Old 02-15-2005, 12:21 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
tokens = params[0].tokenize();

Like Okiesmokie said.
__________________
Skyld
Reply With Quote
  #30  
Old 02-15-2005, 12:31 AM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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
__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
  #31  
Old 02-15-2005, 12:33 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
Well i changed it and it didnt fix it
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #32  
Old 02-16-2005, 09:31 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
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")
Reply With Quote
  #33  
Old 02-16-2005, 10:35 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
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;
}
};

__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #34  
Old 02-16-2005, 11:27 PM
Evil_Trunks Evil_Trunks is offline
Evil
Evil_Trunks's Avatar
Join Date: Dec 2004
Posts: 391
Evil_Trunks is on a distinguished road
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
__________________

Reply With Quote
  #35  
Old 02-17-2005, 01:34 AM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
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.
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #36  
Old 02-17-2005, 04:23 PM
Doahh_p2p Doahh_p2p is offline
Developer
Join Date: Oct 2004
Posts: 187
Doahh_p2p will become famous soon enough
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
Reply With Quote
  #37  
Old 02-17-2005, 10:13 PM
Ajira Ajira is offline
Poont.
Join Date: Oct 2004
Location: NY, USA
Posts: 477
Ajira is on a distinguished road
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.
Reply With Quote
  #38  
Old 02-17-2005, 10:14 PM
falco10291029 falco10291029 is offline
BEst User EVER!
Join Date: Apr 2004
Posts: 1,186
falco10291029 is on a distinguished road
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.....
__________________
BEst Insult ever: If I had a dollar for every brain you DIDNT have, i'd have one dollar!
Reply With Quote
  #39  
Old 02-20-2005, 04:22 AM
Doahh_p2p Doahh_p2p is offline
Developer
Join Date: Oct 2004
Posts: 187
Doahh_p2p will become famous soon enough
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
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 12:12 AM.


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