Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Beginner Scripting is GS2 (https://forums.graalonline.com/forums/showthread.php?t=84243)

maximus_asinus 02-16-2009 09:45 AM

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?

Loriel 02-16-2009 10:54 AM

Quote:

Originally Posted by maximus_asinus (Post 1466930)
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.

Crow 02-16-2009 03:19 PM

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);



Chompy 02-16-2009 04:53 PM

Quote:

Originally Posted by maximus_asinus (Post 1466930)
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.

DustyPorViva 02-16-2009 07:12 PM

Quote:

Originally Posted by Loriel (Post 1466942)
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.

maximus_asinus 02-16-2009 07:51 PM

Quote:

Originally Posted by Chompy (Post 1466960)
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 (Post 1466984)
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?

Crow 02-16-2009 08:09 PM

Quote:

Originally Posted by maximus_asinus (Post 1466994)
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.

maximus_asinus 02-16-2009 08:16 PM

Quote:

Originally Posted by Crow (Post 1466998)
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?

Crow 02-16-2009 08:23 PM

Quote:

Originally Posted by maximus_asinus (Post 1467000)
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.

maximus_asinus 02-16-2009 08:32 PM

Quote:

Originally Posted by Crow (Post 1467002)
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);



Crow 02-16-2009 08:52 PM

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

maximus_asinus 02-16-2009 08:54 PM

Quote:

Originally Posted by Crow (Post 1467013)
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

maximus_asinus 02-16-2009 09:17 PM

Quote:

Originally Posted by Crow (Post 1467002)
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?

Tyhm 02-16-2009 11:48 PM

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.

cbk1994 02-16-2009 11:59 PM

Quote:

Originally Posted by Crow (Post 1467002)
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 (Post 1467021)
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.

maximus_asinus 02-17-2009 12:00 AM

Quote:

Originally Posted by Tyhm (Post 1467079)
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.

Thanks for the clarification. So if I made the script serverside I could achieve my goal in initializing the loop, but since it would put pointless strain on the NPC Server, it would make more sense making it clientside and with playerenters?

I'm going back to my older levels and converting to GS2, and I'm wondering if I change certain tiles and use updateboard to make the changes visible, would the changes be made locally or for everyone in the level, or does it depend on the context I use those commands?

cbk1994 02-17-2009 12:04 AM

Quote:

Originally Posted by maximus_asinus (Post 1467085)
Thanks for the clarification. So if I made the script serverside I could achieve my goal in initializing the loop, but since it would put pointless strain on the NPC Server, it would make more sense making it clientside and with playerenters?

I'm going back to my older levels and converting to GS2, and I'm wondering if I change certain tiles and use updateboard to make the changes visible, would the changes be made locally or for everyone in the level, or does it depend on the context I use those commands?

Serverside, there is a server option (savelevels=true) which when you use updateboard/updateboard2, the changes are actually saved.

maximus_asinus 02-17-2009 12:13 AM

Quote:

Originally Posted by cbk1994 (Post 1467089)
Serverside, there is a server option (savelevels=true) which when you use updateboard/updateboard2, the changes are actually saved.

Okay in my example I have a path that is normally blocked unless Player A shoots an NPC with an arrow. It would be nice for Player A and B to see the changes if they're in the level when the NPC is shot, but if Player C enters he would not see this newly made path. Is such a result possible?

cbk1994 02-17-2009 12:31 AM

Quote:

Originally Posted by maximus_asinus (Post 1467094)
Okay in my example I have a path that is normally blocked unless Player A shoots an NPC with an arrow. It would be nice for Player A and B to see the changes if they're in the level when the NPC is shot, but if Player C enters he would not see this newly made path. Is such a result possible?

It would probably be better to use images for what you want, or even invisible NPCs, that, when shot, stop blocking for x time.

PHP Code:

function onActionProjectile() {
  
dontblock();
  
scheduleevent(3"Block""");
}
function 
onBlock() {
  
blockagain();
}
//#CLIENTSIDE
function onCreated() {
  
setshape(1WIDTH_IN_PIXELSHEIGHT_IN_PIXELS);


Should be able to get the basic gist out of the above code.

Tyhm 02-17-2009 12:47 AM

Yes; to accomplish what you want, you'd just have to set it up so that when the target's hit, for all players in the room, tell their clientsides that the path is clear.

Unfortunately I suck at triggeractions, so I'll leave it to someone else to show you what that script would look like. :-P

maximus_asinus 02-17-2009 03:40 AM

Quote:

Originally Posted by cbk1994 (Post 1467103)
It would probably be better to use images for what you want, or even invisible NPCs, that, when shot, stop blocking for x time.

PHP Code:

function onActionProjectile() {
  
dontblock();
  
scheduleevent(3"Block""");
}
function 
onBlock() {
  
blockagain();
}
//#CLIENTSIDE
function onCreated() {
  
setshape(1WIDTH_IN_PIXELSHEIGHT_IN_PIXELS);


Should be able to get the basic gist out of the above code.

Yes, I agree with you, I probably should use an image, BUT I dislike using images (almost as much as I hate using custom tiles) because I can achieve the same effect without creating a new image.

I have another question, relating to my refusal to using images. Is it possible to draw tiles over a player and make it not block? I read somewhere about Graal using multiple layers for tiles.

Tyhm 02-17-2009 04:15 AM

Umm, yeah? Showimg doesn't block, but I don't know if that's what you're looking for...it's certainly Possible to showimg pics1.png; changeimgpart to a 16x16 tile...
If you want to give yourself a LITTLE less of a heart attack, you could make a Gani of the set of tiles you want...

the last thing I read about Graal using multiple layers for tiles, it turned out they meant the Z axis, and the rest of us were still boned...there's never a quick and easy way to tile a bridge Over a path...you can attachplayer to an NPC of a bridge, but...

cbk1994 02-17-2009 06:35 AM

Quote:

Originally Posted by maximus_asinus (Post 1467166)
Yes, I agree with you, I probably should use an image, BUT I dislike using images (almost as much as I hate using custom tiles) because I can achieve the same effect without creating a new image.

I have another question, relating to my refusal to using images. Is it possible to draw tiles over a player and make it not block? I read somewhere about Graal using multiple layers for tiles.

The code I posted does not require an image :pluffy:

WanDaMan 02-17-2009 11:02 PM

Quote:

Originally Posted by maximus_asinus (Post 1467166)
I have another question, relating to my refusal to using images. Is it possible to draw tiles over a player and make it not block? I read somewhere about Graal using multiple layers for tiles.

It is possible, however; it would probably be easier to use an image. Menion Leah used pics1.png as the image and identified the tiles he wanted for the part using script instead of creating a new image for the tiles he needed.

maximus_asinus 02-20-2009 09:09 PM

How does VECX and VECY work? The Wiki isn't informative at all.

Tigairius 02-20-2009 11:00 PM

Quote:

Originally Posted by maximus_asinus (Post 1468214)
How does VECX and VECY work? The Wiki isn't informative at all.

vecx(dir) and vecy(dir) are the same as doing cos(pi * (dir + 1) % 4 / 2) and sin(pi * (dir + 1) % 4 / 2)

To put it simply, this is how I always remembered it: it will return the direction that something should be moving in relation to the direction that you input.

For example, vecx(3) will return 1, while vecx(1) will return -1:

If your direction is 1 you are facing left, obviously the object should travel -1 (x). If you are facing right, 3, the object could travel 1 (x).

Same relation is for vecy(dir).

maximus_asinus 02-21-2009 12:01 AM

Thanks Tig (damn percent signs gave me 404 error, so I can't quote you).


All times are GMT +2. The time now is 01:43 AM.

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