Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Triggerserver In a Level NPC (https://forums.graalonline.com/forums/showthread.php?t=134268407)

Pandar 07-02-2013 11:44 AM

Triggerserver In a Level NPC
 
I'm not honestly sure how many people care about this at this point, especially when setshape & triggeraction has been such a viable option for a long time now, but I've actually come up with a solution to make this possible that I've personally tested and succeeded with. It's not efficient, but it does get the job done, and if you desperately need a local npc to use client/server interaction without having the npc have a shape, you can use this.

Anyway. First I'll explain the problem that actually causes this to initially not work. The issue is that level npcs simply do not have a name on the clientside of things. Only server. So the issue is that, basically, if you try to use

PHP Code:

triggerserver("npc"this.name"test"); 

you're telling it to trigger to nothing. Now, you'd think "oh I can just get the serverside name," but then comes the issue, if I can't trigger between serverside and clientside, how am I going to get that name? Well it's pretty obvious and easy. Maybe I'm not the first to figure this out, but in case anyone was interested, here you go.

PHP Code:

function onCreated() {
  
setTimer(1);
}

function 
onTimeOut() {
  for (
i:allplayers) {
    if (
i.level == this.level) {
      
i.client.lnpcn this.name;
    }
  }
  
setTimer(1);
}

function 
onActionServerside(f) {
  switch (
f) {
    case 
"f":
      
sendtorc("Pandar is ****ing rad as ****");
      break;
  }
}

//#CLIENTSIDE
function onCreated() { setTimer(1); }

function 
onTimeOut() {
  
this.client.lnpcn;
  
setTimer(1);
}

function 
WhatThe****EverYouWantToTriggerFrom() {
  
triggerserver("npc"this.n"f");


Basically what this does is repeatedly assign everybody in the level a client. flag of the serverside npc name. The npc can then run a constant loop that sets a variable to the serverside name by accessing each player's client flag, and using that to trigger.

Like I said, not sure if this serves anybody any use, but I was ****ing around this morning experimenting different methods of getting triggerserver to work in a Class NPC because I've always wanted to do it, (mostly because of my irrational hatred of triggeraction() ) and when I figured it out I thought I'd share with this lovely (read: vile) community. Also,

pls rep me.

Enjoy. :)

callimuc 07-02-2013 12:45 PM

Quote:

Originally Posted by Pandar (Post 1720117)
PHP Code:

function onTimeOut() {
  for (
i:allplayers) {
    if (
i.level == this.level) {
      
i.client.lnpcn this.name;
    }
  }
  
setTimer(1);



why not just use

PHP Code:

for (i:players) {
  
i.client.lnpcn this.name;


or better

PHP Code:

function onPlayerEnters() {
  
player.client.lnpcn this.name;
  
//on clientside then this.n = player.client.lnpcn;


?

also, wouldnt this stop working if you use several npcs? i'd just suggest to stick with the setshape/triggeraction version like you mentioned it

cbk1994 07-02-2013 12:56 PM

The timeout method is really dumb, this is a much better method:

Quote:

Originally Posted by callimuc (Post 1720124)
PHP Code:

function onPlayerEnters() {
  
player.client.lnpcn this.name;
  
//on clientside then this.n = player.client.lnpcn;



However the following is even better:

PHP Code:

// could use onCreated but onPlayerEnters is just to be safe
function onPlayerEnters() {
  
this.attr[4] = this.name;


Attributes are synced to clientside, so you can avoid polluting the player's flags.

Depending on your situation, a better solution can be to have an actual DB NPC which handles the actions/logic of the level NPC and simply trigger that.

Quote:

Originally Posted by cbk1994 (Post 1541241)
I hope I'm not confusing anyone here, but I've always found it better to use DB NPCs for something like this

PHP Code:

function Shop_Button1.onAction() {  
  if (
checkCost(this.item)) { 
    
Shop_MultiLine1.setText("Danke für den Einkauf");

    
// trigger a DB NPC:
    
triggerServer("npc""ShopControl""buy"this.item);
  } 
  else 
Shop_MultiLine1.setText("Nich genug Geld");  


then have a DB NPC named "ShopControl"

PHP Code:

function onActionServerSide() {
  
// The parameters are received from the client-side 
  // in an array like so: {"buy", "jeep"} 
  // Assuming "jeep" was in this.item when it was triggered 
  
if (params[0] == "buy") { 
    switch (
params[1]) { 
      case 
"jeep"
        
// Check to see if they enough rupees 
        
temp.cost 15
        if (
player.rupees >= temp.cost) { 
          
// Add weapon and deduct rupees from player  
          
addweapon("Jeep2"); 
          
player.rupees -= temp.cost
        } 
      break; 
    } 
  }  




Pandar 07-02-2013 01:56 PM

I'm aware @ the timeout method being dumb, the only reason I used that is because I wanted it to be constantly running for testing purposes. I wouldn't use it in an actual NPC. The attribute idea is pretty great, I actually didn't think of that.

And yeah, I know in most situations you can just use a DB Npc to handle all level NPC trigger needs -- that's why I opened the thread by saying that it's probably not all that useful. I just thought it was neat that I got triggerserver to work and figured I'd share.


EDIT: Post 69 ajajaja.


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

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