Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   quick scripting question (https://forums.graalonline.com/forums/showthread.php?t=86733)

[email protected] 07-06-2009 01:38 PM

quick scripting question
 
Hello.

Say I wanted to make a bank and the account script was going to go into npc-control. What would I put in that specified object to join it to an npc?

like when its a class, you would do:

join (classname);

is it :

join (npcname);

?

thanks,

jamerson

Twinny 07-06-2009 02:39 PM

The only thing that can be in a join() is a class.

I'm not quite following what you want, can you be more specific?

Ronnie 07-06-2009 04:41 PM

You mean a DB-NPC?

fowlplay4 07-06-2009 06:34 PM

I tend to think of classes as "function packs" for existing npcs, but here's an example of how they work. ( I assume that what's you don't understand. )

Class: example
PHP Code:

function randomClassFunc() {
  echo(
"success!");


Then in your DB-NPC:

PHP Code:

function onCreated() {
  
join("example");
  
randomClassFunc(); // Would echo "success!" on NC.



DustyPorViva 07-06-2009 06:56 PM

Also, it is
join("classname");
not
join (classname);
Firstly, join, like other functions, should not have a space between the function name and the parenthesis. Secondly, you must enclose strings(like the name of a class or weapon) in quotation marks, or else Graal will be trying to find a variable.

[email protected] 07-07-2009 02:29 AM

What im asking is how do you make a level npc have the same function as the db-npc. Its a bank system, and when you update the level the bank account money n your account resets, thats why i want to use a db npc. How do I make the npc in the level use the script thats in a db npc?

fowlplay4 07-07-2009 02:56 AM

Quote:

Originally Posted by [email protected] (Post 1504793)
What im asking is how do you make a level npc have the same function as the db-npc. Its a bank system, and when you update the level the bank account money n your account resets, thats why i want to use a db npc. How do I make the npc in the level use the script thats in a db npc?

Oh well there's public functions.

In your DB-NPC (named Example in this case):

PHP Code:

public function onRandFunc() {
  echo(
"success!");


Then in your level npc:

PHP Code:

function onCreated() {
  
findnpc("Example").onRandFunc(); // Would echo success! on RC



cbk1994 07-07-2009 03:09 AM

Quote:

Originally Posted by fowlplay4 (Post 1504794)
Oh well there's public functions.

In your DB-NPC (named Example in this case):

PHP Code:

public function onRandFunc() {
  echo(
"success!");


Then in your level npc:

PHP Code:

function onCreated() {
  
findnpc("Example").onRandFunc(); // Would echo success! on RC



No reason at all to use findNPC.

PHP Code:

Example.func(); 


xXziroXx 07-07-2009 05:29 PM

Quote:

Originally Posted by cbk1994 (Post 1504798)
No reason at all to use findNPC.

Personal preference. I use it for code readability.

fowlplay4 07-07-2009 05:55 PM

Quote:

Originally Posted by xXziroXx (Post 1504910)
Personal preference. I use it for code readability.

I use it because I have trust issues with variable names.

xXziroXx 07-07-2009 06:43 PM

Quote:

Originally Posted by fowlplay4 (Post 1504916)
I use it because I have trust issues with variable names.

That too.

Tigairius 07-07-2009 09:24 PM

You can also do a class like this:
PHP Code:

function hello() {
  echo(
"hello from class");


then a script like this:

PHP Code:

function onCreated() {
  
join("classname");
  
classname::hello();
  
hello();
}
function 
hello() {
  echo(
"hello from script");


This way you can ensure that you're calling the function in the class.


All times are GMT +2. The time now is 02:17 AM.

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