Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Adding Scripts to NPC (https://forums.graalonline.com/forums/showthread.php?t=134262659)

mrnothersan 04-02-2011 10:11 PM

Adding Scripts to NPC
 
Hi,

How do I add commands to the NPC user?
For example if someone chats to the npc user and says "/eventsapp" they get sent back the events team staff application automatically?

Thanks

Cubical 04-02-2011 10:16 PM

A combination of these two functions, you could have just looked through the starting guide in the wiki and figured it out.
PHP Code:

onPlayerChats()
sendpm() 


iBeatz 04-02-2011 10:26 PM

For a weapon:

PHP Code:

function onActionServerSide(){
 if(
params[0] == "Getets"){
  
player.sendpm("put message here");
 }
}
//#CLIENTSIDE
function onPlayerChats(){
 if(
player.chat == "/eventsapp"){
  
triggerserver("gui",name,"Getets");
 }



Cubical 04-02-2011 10:30 PM

If you want to add more than one 'command' which i'm sure you will instead of doing elseif or else you can also use the switch statement. There's a post that Zero(zokemon) did explaining it. I think it was called spoils of the switch statement.

Deas_Voice 04-04-2011 07:48 PM

...i think he means pm'ing the NPC-Server

cbk1994 04-04-2011 09:26 PM

In that case, in Control-NPC:

PHP Code:

function onCreated() {
  
this.setPM(""); // reset the reply PM
}

function 
onInitialized() {
  
this.trigger("created"); // if the server restarts
}

// the parameters are lines
function onPM(p0p1p2p3) { // first parameter isn't used
  
if (p1 == "eventsapp") {
    
player.sendPM("Events Application:\nStuff here!");
  }



fowlplay4 04-04-2011 09:33 PM

It's actually lines.

I.e:
Quote:

Hello World
This is a pm.
Results in...

PHP Code:

params = {
  
""// Some sort of reference, useless though since player. is accessible.
  
"Hello World",
  
"This is a pm."
}; 

Therefore...

PHP Code:

function onPM(p0p1) {
  
// If you need the whole message in a string (delete this otherwise)
  // you can put it together like this:
  
for (temp.lineparams.subarray(1)) {
    
temp.message @= temp.line NL "";
  }
  
// Or just check the first line
  
if (p1 == "eventsapp") {
    
player.sendPM("Events Application:\nStuff here!");
  }




All times are GMT +2. The time now is 04:30 AM.

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