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 03-18-2004, 03:03 AM
wonderboysp2p wonderboysp2p is offline
Registered User
wonderboysp2p's Avatar
Join Date: Sep 2002
Location: -Wonderboy
Posts: 537
wonderboysp2p is on a distinguished road
Send a message via AIM to wonderboysp2p
Arrow -now what am i doing wrong?

ive been nored and working on a rescript of the inventory system and its comin along pretty good

the script works fine except for ONE thing! it repeats the "replace string" -for adding to the quantity of the item- twice for seom hideously odd reason.

if (actionact) {
if (lindexof(#s(this.item),client.inv)==-1){
addstring client.inv,Apple;
addstring client.invcount,1;
}
else {
replacestring client.invcount,lindexof(#s(this.item),client.inv) ,#v(strtofloat(#I(client.invcount,lindexof(#s(this .item),client.inv)))+1);
}
}

the action command is simply

if (keypressed){
if (keydown(6)){
triggeraction playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playe rdir)*2,act,;
}
}

any help, id appreciate ^_^
__________________

we are the llama FORUms!!!EWQ Ce13d5423f23!! 2e1 @$6tgv3uy65!
Reply With Quote
  #2  
Old 03-18-2004, 03:29 AM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
either keypressed is running twice or that part of the script isn't the problem, do you have a timeout running around the execution of this script? (within the same script I mean)
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
  #3  
Old 03-18-2004, 03:44 AM
wonderboysp2p wonderboysp2p is offline
Registered User
wonderboysp2p's Avatar
Join Date: Sep 2002
Location: -Wonderboy
Posts: 537
wonderboysp2p is on a distinguished road
Send a message via AIM to wonderboysp2p
No timeouts at all.... i ran debugger on the actionact part and it executes twice.. i havent debugged on keypressed yet


Any ideas on how ta fix it?
__________________

we are the llama FORUms!!!EWQ Ce13d5423f23!! 2e1 @$6tgv3uy65!
Reply With Quote
  #4  
Old 03-18-2004, 05:32 AM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
does this happen for others aswell?
I'd say restart the npc server, but that may not be needed, or be the problem... ooh! do it anyway!
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
  #5  
Old 03-18-2004, 08:01 AM
DarkShadows_Legend DarkShadows_Legend is offline
Cult of the Winky
DarkShadows_Legend's Avatar
Join Date: Apr 2003
Location: Florida
Posts: 614
DarkShadows_Legend is on a distinguished road
Send a message via AIM to DarkShadows_Legend
Question hmmm...

If you press the key 'a' then it sends the triggeraction. As long as the key is down it will continue to send the triggeraction.

I assume the part sending the triggeraction is a weapon and the other is an object. Wouldn't you have to destroy the object after the player gets it so the player will not get it added again?
__________________
- Criminal X

"I rather be hated for being myself, than be liked for being what you like best. I go above the influence, not under." - Me
Reply With Quote
  #6  
Old 03-18-2004, 09:07 AM
wonderboysp2p wonderboysp2p is offline
Registered User
wonderboysp2p's Avatar
Join Date: Sep 2002
Location: -Wonderboy
Posts: 537
wonderboysp2p is on a distinguished road
Send a message via AIM to wonderboysp2p
Re: hmmm...

Quote:
Originally posted by DarkShadows_Legend
Wouldn't you have to destroy the object after the player gets it so the player will not get it added again?

what if there's twelve of the items in that pile and you only want to pick up 3 of them?
__________________

we are the llama FORUms!!!EWQ Ce13d5423f23!! 2e1 @$6tgv3uy65!
Reply With Quote
  #7  
Old 03-18-2004, 03:12 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Re: -now what am i doing wrong?

Quote:
Originally posted by wonderboysp2p
-now what am i doing wrong?
You are not using code tags and you named this thread so it tells nothing about your problem.

I think the problem is that you use keypressed and keydown. You should either figure out the key that was pressed by the #p thingies you get along with keypressed, or you should use a timeout loop and check whether the key was already pressed in the previous frame (by doing this.oldkeydown = keydown(6) after everything).
Otherwise, any keypress while A is pressed will trigger the action again. It is not true, though, that this gets looped as someone said.

Other than that, you should do some precalculating instead of writing everything in the replacestring line. It helps not only readability but also might be more efficient, if it takes less time to access variables than it takes to call lindexof and stuff. But readability still wins.
NPC Code:
  else {
itemindex = lindexof(#s(this.item),client.inv);
itemcount = strtofloat(#I(client.invcount, itemindex)) + 1;
replacestring client.invcount,itemindex,#v(itemcount);
}
destroy; // Assuming it is supposed to be "picked up" now


Next, you might consider allowing items to not only have a type but also a quantity so if many items of the same type are close, they get put together into one NPC.

And have a look at my item system, perhaps.
Reply With Quote
  #8  
Old 03-19-2004, 02:29 AM
wonderboysp2p wonderboysp2p is offline
Registered User
wonderboysp2p's Avatar
Join Date: Sep 2002
Location: -Wonderboy
Posts: 537
wonderboysp2p is on a distinguished road
Send a message via AIM to wonderboysp2p
no idea why it was repeating the keydown command but i DID end up fixing it by making a quick pause in the (actionact) part
NPC Code:

if (actionact) {
if (this.itemcount>0){
if (this.wait==0){
if (lindexof(#s(this.item),client.inv)==-1){
addstring client.inv,#s(this.item);
addstring client.invcount,1;
this.itemcount--;
pause();
}
else {
replacestring client.invcount,lindexof(#s(this.item),client.inv) ,#v(strtofloat(#I(client.invcount,lindexof(#s(this .item),client.inv)))+1);
this.itemcount--;
pause();
}
}
update();
}
else {
destroy;
}
}



im all curious about the repeatingness now... X_x a bug?
__________________

we are the llama FORUms!!!EWQ Ce13d5423f23!! 2e1 @$6tgv3uy65!
Reply With Quote
  #9  
Old 03-19-2004, 04:19 AM
Andy0687 Andy0687 is offline
Enigma
Join Date: Feb 2002
Posts: 1,072
Andy0687 is on a distinguished road
Quote:
Originally posted by wonderboysp2p
im all curious about the repeatingness now... X_x a bug?
Mabye not

i was intrested how you had

NPC Code:

if (keypressed) {
if (keydown(6)) {
}
}



i was unaware that was possibile, and perhaps thats the reason it is repeating, because you had keydown, which reads fast i thought, so when the key is pressed and its reading it, seems like twice before you can get your finger up.

No bug i dont think.
__________________
Reply With Quote
  #10  
Old 03-19-2004, 04:50 AM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
... Actually none of them repeat, unless you hold them down too long, make sure your keyboard settings don't repeat keys too fast. If not that, it's lag, use a timeout and check that the key wasn't down last time it was checked.

weapon;
NPC Code:

//#CLIENTSIDE
if (keypressed) {
if (keydown(5)) {
this.c++;
setplayerprop #c,#v(this.c);
}
if (strequals(#p(1),d)) {
this.d++;
setplayerprop #c,#v(this.d);
}
if (keydown2(keycode(a),false)) {
this.a++;
setplayerprop #c,#v(this.a);
}
}



toAndy: keydown is a flag, it can't "read fast"
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial
Reply With Quote
  #11  
Old 03-19-2004, 09:13 PM
Andy0687 Andy0687 is offline
Enigma
Join Date: Feb 2002
Posts: 1,072
Andy0687 is on a distinguished road
Quote:
Originally posted by Dach

toAndy: keydown is a flag, it can't "read fast"
I was thinking of when you did something like

NPC Code:

if (timeout) {
if (keydown(#)) {
}
}



that perhaps that same thing was applying itsself here.
__________________
Reply With Quote
  #12  
Old 03-19-2004, 11:00 PM
protagonist protagonist is offline
Banned
protagonist's Avatar
Join Date: May 2003
Location: CAW
Posts: 5,586
protagonist is on a distinguished road
Send a message via AIM to protagonist Send a message via MSN to protagonist
Quote:
Originally posted by Dach

toAndy: keydown is a flag, it can't "read fast"
Keypressed can make it be read fast, though.
Reply With Quote
  #13  
Old 03-19-2004, 11:13 PM
WanDaMan WanDaMan is offline
Master Tux
WanDaMan's Avatar
Join Date: Aug 2002
Location: England, United Kingdom
Posts: 5,571
WanDaMan is a jewel in the roughWanDaMan is a jewel in the rough
Send a message via MSN to WanDaMan
Quote:
Originally posted by protagonist


Keypressed can make it be read fast, though.
keypressed > sensetive > timeout=.1
__________________
V$:CONFL16T
Reply With Quote
  #14  
Old 03-20-2004, 01:55 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
I never liked keypressed
Reply With Quote
  #15  
Old 03-20-2004, 02:12 AM
Tyrial Tyrial is offline
The Shiznic
Join Date: Dec 2001
Location: Sweden > Stockholm
Posts: 2,411
Tyrial is an unknown quantity at this point
Quote:
Originally posted by Loriel
I never liked keypressed
What do you like? keysmashed?
'

hehe i like keydown2
__________________
-Mher Avetian
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 07:37 PM.


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