Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   dunno no the name ? (https://forums.graalonline.com/forums/showthread.php?t=87603)

littlekinky 08-26-2009 12:52 AM

dunno no the name ?
 
Well i was wondering how to do this when a player enters and levels and image appears would that jsut be simply something like

PHP Code:

//#CLIENTSIDE

function Playerenters.onShow() {
  
   
showimg1"imagename"
player.- -1.5player.1.8 );



fowlplay4 08-26-2009 01:01 AM

There's onPlayerEnters, that is called when the player enters a level.

PHP Code:

//#CLIENTSIDE
function onPlayerEnters() {
  
// Show Image Script here



cyan3 08-26-2009 03:00 AM

if (playerenters) can be used if you've already called a function.

PHP Code:

//#CLIENTSIDE
function onCreated() {
 if (
playerenters) {
   
//Stuff
 
}



Mark Sir Link 08-26-2009 03:03 AM

Quote:

Originally Posted by cyan3 (Post 1518509)
if (playerenters) can be used if you've already called a function.

PHP Code:

//#CLIENTSIDE
function onCreated() {
 if (
playerenters) {
   
//Stuff
 
}



Don't do this, just use onPlayerEnters() to detect if a player has entered a level.

fowlplay4 08-26-2009 03:04 AM

Quote:

Originally Posted by cyan3 (Post 1518509)
if (playerenters) can be used if you've already called a function.

PHP Code:

//#CLIENTSIDE
function onCreated() {
 if (
playerenters) {
   
//Stuff
 
}



That's mixing GS1 and GS2, which is bad.

Also for future note you shouldn't have to call onCreated or onPlayerEnters unless you're re-initializing your script for whatever reason.

I.e:

PHP Code:

function whatever() {
  
// whatever "calls" onCreated();
  
onCreated();


Edit: lol, two negative verdicts.

cyan3 08-26-2009 03:04 AM

Quote:

Originally Posted by Mark Sir Link (Post 1518510)
Don't do this, just use onPlayerEnters() to detect if a player has entered a level.

Wouldn't that not work if it's called under another function?

Quote:

Originally Posted by fowlplay4 (Post 1518512)
That's mixing GS1 and GS2, which is bad.

I know it was used in GS1 but somebody told me a while back that it works in GS2 if it's called under a function.

Mark Sir Link 08-26-2009 03:09 AM

Quote:

Originally Posted by cyan3 (Post 1518513)
Wouldn't that not work if it's called under another function?

I don't understand your question. the action onPlayerEnters is called every time a player enters a level.
Quote:

I know it was used in GS1 but somebody told me a while back that it works in GS2 if it's called under a function.
I haven't done a whole lot of work lately so I can't say this for sure but onCreated() may not always be called when a player enters if they have entered previously (instances of a class maybe?)

fowlplay4 08-26-2009 03:15 AM

Quote:

Originally Posted by cyan3 (Post 1518513)
I know it was used in GS1 but somebody told me a while back that it works in GS2 if it's called under a function.

Well I believe that would be useless to put in there, because I assume you want to be called when you do both onCreated and onPlayerEnters.

If you need it to update/do script every time you enter a level you can get away with only using onPlayerEnters(), if it's only a one time thing use onCreated().

Anyway the whole reason onPlayerEnters() exists is so you don't have to use "if (playerenters)" ever again.

cyan3 08-26-2009 03:15 AM

Quote:

Originally Posted by Mark Sir Link (Post 1518515)
I haven't done a whole lot of work lately so I can't say this for sure but onCreated() may not always be called when a player enters if they have entered previously (instances of a class maybe?)

Maybe because was a bad example, this is the script somebody said will work.

PHP Code:

function onTimeout() {
 if (
playerenters) {
  
setTimer(0.5);
   
setani("sit",NULL);
 }


Quote:

Originally Posted by fowlplay4 (Post 1518518)
Well I believe that would be useless to put in there, because I assume you want to be called when you do both onCreated and onPlayerEnters.

If you need it to update/do script every time you enter a level you can get away with only using onPlayerEnters(), if it's only a one time thing use onCreated().

My example was bad, you would call both as a different function. It would work exactly the same if you used function onPlayerEnters() instead of calling it under onCreated().

cbk1994 08-26-2009 03:20 AM

Quote:

Originally Posted by cyan3 (Post 1518519)
Maybe that was a bad example, this is the script somebody said will work.

PHP Code:

function onTimeout() {
 if (
playerenters) {
  
setTimer(0.5);
   
setani("sit",NULL);
 }




My example was bad, you would call both as a different function if it's onCreated()

I don't mean to be rude, but you should definitely not be giving advice like that when you don't know quite what you're talking about.

Stuff like "if (playerenters)" is GS1, and makes no sense. The idea of coding is creating readable code that flows smoothly. Using stuff like that in combination with GS2 leads to messy code that is hard to follow.

DustyPorViva 08-26-2009 03:20 AM

Quote:

Originally Posted by cyan3 (Post 1518509)
if (playerenters) can be used if you've already called a function.

PHP Code:

//#CLIENTSIDE
function onCreated() {
 if (
playerenters) {
   
//Stuff
 
}



onPlayerEnters was originally an event. Something that is called in response to an action(in this case, the player entering). However, in GS1, events were checked in if statements just like conditions(1 == 1), hence why it might be possible to do if (playerenters).

Regardless, onCreated is an event as well(as such, in GS2 both are functions and are called upon their respective actions), so the equivalent in GS1 would have been:
if (playerenters && created) {}
Which is impossible(I'm assuming) because it would be attempting to check if the NPC was created AND the player entered at the exact same moment.

Simply, the player entering the room is not a condition(which are what if checks are for) and shouldn't be treated as such. It is not a true or false situation, but instead an action.

Fowlplay got it right in his first post. However, to do something similar to what your post is implying would be something like this:
PHP Code:

function onCreated() {
  
// do stuff
}

function 
onPlayerEnters() {
  
onCreated();



cyan3 08-26-2009 03:30 AM

Quote:

Originally Posted by cbk1994 (Post 1518520)
I don't mean to be rude, but you should definitely not be giving advice like that when you don't know quite what you're talking about.

I shouldn't have taken any notice of the person who told me it works because they probably didn't know either.


All times are GMT +2. The time now is 12:46 AM.

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