Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-02-2013, 11:44 AM
Pandar Pandar is offline
Babylon Co-Manager
Pandar's Avatar
Join Date: Jan 2007
Location: New York
Posts: 68
Pandar has a spectacular aura aboutPandar has a spectacular aura about
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.
__________________
R.I.P. Graal (1998 - 2004)
Reply With Quote
  #2  
Old 07-02-2013, 12:45 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by Pandar View Post
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
__________________
MEEP!
Reply With Quote
  #3  
Old 07-02-2013, 12:56 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
The timeout method is really dumb, this is a much better method:

Quote:
Originally Posted by callimuc View Post
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 View Post
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; 
    } 
  }  

__________________
Reply With Quote
  #4  
Old 07-02-2013, 01:56 PM
Pandar Pandar is offline
Babylon Co-Manager
Pandar's Avatar
Join Date: Jan 2007
Location: New York
Posts: 68
Pandar has a spectacular aura aboutPandar has a spectacular aura about
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.
__________________
R.I.P. Graal (1998 - 2004)
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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