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-16-2009, 09:45 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,746
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
Beginner Scripting is GS2

Okay I have loads of questions but I'll try reading all of the Graal Bible thoroughly before I unload them all on you guys/gals.

First off, I am busy converting many of the predefined objects I use. I 'converted' Stefan's light NPC, basically searching for the functions in Graal Bible and pasting them in, but I'm not sure if I have it correct, nor do I think it is as efficient as it could be.
HTML Code:
function onCreated() {
  setimg(light2.png);
  dontblock();
}
//#CLIENTSIDE
function onPlayerEnters() {
  drawaslight();
  setcoloreffect(1, 1, 1, .99);
  setzoomeffect(3);
}
I'll be back with more questions!

EDIT: I meant "in GS2" and not "is GS2". Someone might read that and get insulted :3
EDIT: Is there a server open to a Classic subscriber where I could test my scripts for trial and error, rather than me asking each question?
EDIT: What is the difference between onCreated and onPlayerEnters? Does the NPC server process an NPC that uses onCreated immediately, without the player being in the level? If I used onCreated clientside would it be treated differently, more like onPlayerEnters?
__________________
Save Classic!

Last edited by maximus_asinus; 02-16-2009 at 10:16 AM..
Reply With Quote
  #2  
Old 02-16-2009, 10:54 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
Quote:
Originally Posted by maximus_asinus View Post
EDIT: What is the difference between onCreated and onPlayerEnters? Does the NPC server process an NPC that uses onCreated immediately, without the player being in the level? If I used onCreated clientside would it be treated differently, more like onPlayerEnters?
Every NPC is created exactly once, but players enter and leave levels all the time.
Reply With Quote
  #3  
Old 02-16-2009, 03:19 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
First, I suggest posting code on the forums inbetween [php][/php] tags. At least we have some syntax highlighting then.
Second, you got a small but important error in your code. You have to place quotation marks around strings, like light2.png in your case. This should work:

PHP Code:
function onCreated() {
  
setimg("light2.png");
  
dontblock();
}
//#CLIENTSIDE
function onPlayerEnters() {
  
drawaslight();
  
setcoloreffect(111.99);
  
setzoomeffect(3);

Reply With Quote
  #4  
Old 02-16-2009, 04:53 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by maximus_asinus View Post
EDIT: Is there a server open to a Classic subscriber where I could test my scripts for trial and error, rather than me asking each question?
Indeed there is, it's called Testbed Server. If you want RC, ou'll have to contact Tig, either by email, forum pm, AIM or in-game.
__________________
Reply With Quote
  #5  
Old 02-16-2009, 07:12 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by Loriel View Post
Every NPC is created exactly once, but players enter and leave levels all the time.
For elaboration, onCreated is created once per session. So it'll be called every time the NPC is created... when the player first logs on(for weapons), when the level/NPC is updated, when the player enters the level for the first time and the NPC is created.
Reply With Quote
  #6  
Old 02-16-2009, 07:51 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,746
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
Quote:
Originally Posted by Chompy View Post
Indeed there is, it's called Testbed Server. If you want RC, ou'll have to contact Tig, either by email, forum pm, AIM or in-game.
I'll be sure to contact him.

Quote:
Originally Posted by DustyPorViva View Post
For elaboration, onCreated is created once per session. So it'll be called every time the NPC is created... when the player first logs on(for weapons), when the level/NPC is updated, when the player enters the level for the first time and the NPC is created.
Hmm, I'm still confused. Why couldn't I put all of my script into a onCreated function? Would it make a difference?
__________________
Save Classic!
Reply With Quote
  #7  
Old 02-16-2009, 08:09 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 maximus_asinus View Post
Hmm, I'm still confused. Why couldn't I put all of my script into a onCreated function? Would it make a difference?
Depends. Imagine you got an npc which position shall be reset whenever the player enters the level again/reconnects. You would use the onPlayerEnters() event then.
Reply With Quote
  #8  
Old 02-16-2009, 08:16 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,746
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
Quote:
Originally Posted by Crow View Post
Depends. Imagine you got an npc which position shall be reset whenever the player enters the level again/reconnects. You would use the onPlayerEnters() event then.
Okay I think I get you. For example, lets say I wanted to create a timeout loop, it would be more efficient to start the timeout in onCreated rather than onPlayerEnters because I don't need to have the timeout sent everytime the player enters?
__________________
Save Classic!
Reply With Quote
  #9  
Old 02-16-2009, 08:23 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 maximus_asinus View Post
Okay I think I get you. For example, lets say I wanted to create a timeout loop, it would be more efficient to start the timeout in onCreated rather than onPlayerEnters because I don't need to have the timeout sent everytime the player enters?
That's actually a quite interesting question. I rarely use any timeouts in level npcs, so I don't even know what would happen if you would put it inside onCreated(). It might aswell just be called once and stop when the player leaves the level. I'm completely unsure about this one though. If we assume smashing it into onCreated() works equally as well as putting it into onPlayerEnters(), I don't think there are any efficiency differences.
Reply With Quote
  #10  
Old 02-16-2009, 08:32 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,746
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
Quote:
Originally Posted by Crow View Post
That's actually a quite interesting question. I rarely use any timeouts in level npcs, so I don't even know what would happen if you would put it inside onCreated(). It might aswell just be called once and stop when the player leaves the level. I'm completely unsure about this one though. If we assume smashing it into onCreated() works equally as well as putting it into onPlayerEnters(), I don't think there are any efficiency differences.
I'll let you guys figure that one out, in the meantime I have more questions.

How about this script? If placed in a level it would put the imagepart at the selected location, correct? Would there be any unexpected behavior (this is why I need a place to test )
PHP Code:
//#CLIENTSIDE
function onCreated() {
  
this.48.5;
  
this.18.5;
  
setimgpart("lampanimation.gif"002036);

__________________
Save Classic!
Reply With Quote
  #11  
Old 02-16-2009, 08:52 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
Correct. To be a bit more specific, it would move the npc this is in to the specified position, then set the image. Unexpected behavior? Depends on what you want this to be. Just a simple lamp? Nothing unexpected. Though this will block by default. But you should already know this ;D
Reply With Quote
  #12  
Old 02-16-2009, 08:54 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,746
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
Quote:
Originally Posted by Crow View Post
Correct. To be a bit more specific, it would move the npc this is in to the specified position, then set the image. Unexpected behavior? Depends on what you want this to be. Just a simple lamp? Nothing unexpected. Though this will block by default. But you should already know this ;D
It is on a wall, I hope players don't get up there :P
__________________
Save Classic!
Reply With Quote
  #13  
Old 02-16-2009, 09:17 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,746
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
Quote:
Originally Posted by Crow View Post
That's actually a quite interesting question. I rarely use any timeouts in level npcs, so I don't even know what would happen if you would put it inside onCreated(). It might aswell just be called once and stop when the player leaves the level. I'm completely unsure about this one though. If we assume smashing it into onCreated() works equally as well as putting it into onPlayerEnters(), I don't think there are any efficiency differences.
You've said that you don't use timeouts in level NPCs, is that because of security, efficiency/performance, or just personal preference?
__________________
Save Classic!
Reply With Quote
  #14  
Old 02-16-2009, 11:48 PM
Tyhm Tyhm is offline
Psionic Youth
Tyhm's Avatar
Join Date: Mar 2001
Location: Babord, West Graal Deaths:1009 Kills:1
Posts: 5,635
Tyhm has a spectacular aura about
if you put a timeout in if(created):
Serverside: it's a lot like playerenters, because created's called once Ever for the Entire Server - which is often also when a player enters - but it could hypothetically start a script for an empty room. I guess it's useful if that's what you're going for - this event's going to happen whether anyone's here to see it or not - but generally it's good practice to, if a timeout happens when playerscount<1, do nothing until playerenters.
Clientside: dangerous, as it starts the loop only once per session; if you leave the room, the timeout stalls, and when you return it doesn't re-start.
__________________
"Whatever," said Bean, "I was just glad to get out of the toilet."

"Power does not corrupt. Fear corrupts, perhaps the fear of a loss of power."- John Steinbeck
"I'm only acting retarded, what's your excuse?" queried the Gord.
- My pet, the Levelup Gnome

http://forums.graalonline.com/forums...&postcount=233
Reply With Quote
  #15  
Old 02-16-2009, 11:59 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
That's actually a quite interesting question. I rarely use any timeouts in level npcs, so I don't even know what would happen if you would put it inside onCreated(). It might aswell just be called once and stop when the player leaves the level. I'm completely unsure about this one though. If we assume smashing it into onCreated() works equally as well as putting it into onPlayerEnters(), I don't think there are any efficiency differences.
It tends to die when the player leaves the level. In a recent script, I just called onTimeOut() when the player enters, restarting the timeout but not resetting any of the variables.

Quote:
Originally Posted by maximus_asinus View Post
You've said that you don't use timeouts in level NPCs, is that because of security, efficiency/performance, or just personal preference?
Normally it's not really needed. Most of the time you need the timeout no matter where the player is, so you put it in a weapon.
__________________
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 09:44 AM.


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