Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Train Script Problem (https://forums.graalonline.com/forums/showthread.php?t=134264461)

Gunderak 09-03-2011 09:01 AM

Train Script Problem
 
Basically im making a train that moves on tracks by its self, but iv ran into a problem.
the tracks are npcs that set images to whatever track piece it is.
is there any way to check if a npc is touching a certain npc and set its this.mode = whatever depending on whats in the npc its touching?
thanks in advanced.
im sure theres a way to do it :rolleyes:

cbk1994 09-03-2011 09:15 AM

You can find all the NPCs at one point by doing something like

PHP Code:

for (temp.npc findAreaNPCs(xy0.10.1)) {
  echo(
"joined classes: " temp.npc.joinedclasses);


Then just figure out which NPC you're looking for based on the joined classes or some other variable. Keep in mind it's the actual NPC object, so you can access its variables ("this.").

Gunderak 09-03-2011 09:18 AM

with the for findAreaNPCs(x, y, 0.1, 0.1)
what are the 0.1's?

cbk1994 09-03-2011 09:21 AM

Quote:

Originally Posted by Gunderak (Post 1666837)
with the for findAreaNPCs(x, y, 0.1, 0.1)
what are the 0.1's?

Directly from the wiki:

Quote:

Originally Posted by The Wiki
findareanpcs(float, float, float, float) - returns object - returns an array of all npcs at the specified rectangle (x,y,width,height)


Gunderak 09-03-2011 09:22 AM

is there any way to change another npcs variable by some command like findnpc("whatever").this.mode = ?
if i made it join to a class how would i change the class variables via a script?

cbk1994 09-03-2011 09:28 AM

Quote:

Originally Posted by Gunderak (Post 1666840)
is there any way to change another npcs variable by some command like findnpc("whatever").this.mode = ?
if i made it join to a class how would i change the class variables via a script?

The this prefix refers to the current object. If you did it as you proposed (which wouldn't work since you can't use findNPC for local NPCs (level NPCs)), you'd be setting this.this.mode. In the example I gave above,

PHP Code:

temp.npc.variableName value

As I said, temp.npc is the actual NPC object.

What do you mean by class variables? That doesn't make any sense, classes are joined to an object. They don't have separate sets of variables.

Gunderak 09-05-2011 04:16 PM

whoever repped me for "being a disgrace to the 'scripter' title"
these forums are a place to learn, i am relativly new to scripting.
so please in future dont judge people over their scripting ability.
if this is your outlook on life i really dont think these forums are the place for you.

@cbk1994 i mean class variables as in if a class has this.whatever = whatever;

furry_mougle 09-05-2011 04:21 PM

Quote:

Originally Posted by Gunderak (Post 1667137)
whoever repped me for "being a disgrace to the 'scripter' title"
these forums are a place to learn, i am relativly new to scripting.
so please in future dont judge people over their scripting ability.
if this is your outlook on life i really dont think these forums are the place for you.

@cbk1994 i mean class variables as in if a class has this.whatever = whatever;

Aren't there special flags within the NPC with vars that you can write to? Just join your class to your NPC and redefine them I guess?

Gunderak 09-06-2011 06:45 AM

ahh thats a batter idea.
can i put
PHP Code:

function onCreated() {
this.join("whatever");
this.mode "idle";


would it still go to on created? or would it stop and go to the class?
im at work so i cant test it.

cbk1994 09-06-2011 12:58 PM

What do you mean by "go to the class"? You seem to have a misunderstanding of how classes work. It doesn't create another object or stop execution of the current one. Imagine the class' script being copied and pasted into the NPC you join it to. onCreated in classes will be triggered if you join the class to something.

Gunderak 09-07-2011 01:11 AM

thanks i tested it at home, i thought if i joined it to a class seeming my class had a timeout it would go execute my class and stay on the class because its looping.


All times are GMT +2. The time now is 07:59 AM.

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