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
  #16  
Old 01-06-2014, 09:38 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
Quote:
Originally Posted by i8bit View Post
Oh yeah, good observation. What if I don't make it loop and it just checks for players/NPCs in that 0.05 time range, triggers the actions, then destroys?
Should work if you only want it to send the trigger once. Just call this.destroy(); after sending the trigger.
__________________
Reply With Quote
  #17  
Old 01-06-2014, 11:25 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
Originally Posted by cbk1994 View Post
Should work if you only want it to send the trigger once. Just call this.destroy(); after sending the trigger.
So I ran into a little bit of issues. I discovered I need to destroy the block serverside. How would I trigger a serverside function in clientside?

I tried this in the clientside

PHP Code:
triggerserver("npc"this.name"destroy"
and this in the serverside..

PHP Code:
function onActionServerSide(){
 if (
params[0] == "destroy"){
  
destroy();
  }
 } 
it doesn't work so can you tell me what I'm doing wrong please?
Reply With Quote
  #18  
Old 01-07-2014, 11:31 AM
Torankusu Torankusu is offline
Elite Member
Torankusu's Avatar
Join Date: Jun 2001
Posts: 10,065
Torankusu is a jewel in the roughTorankusu is a jewel in the rough
Is this in a class or level npc?

Also, are you going to be using this in a situation where the blocks appearance and location needs to be:
A.) The same for all players in the level
Or
B.) Can be different for all players in the level.

Some good suggestions previously listed here, but there are potentially a lot of ways to cheat this on the clientside as well.
__________________
Quote:
Originally posted by Spark910
Think befreo you type.
Reply With Quote
  #19  
Old 01-07-2014, 12:00 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
Originally Posted by Torankusu View Post
Is this in a class or level npc?

Also, are you going to be using this in a situation where the blocks appearance and location needs to be:
A.) The same for all players in the level
Or
B.) Can be different for all players in the level.

Some good suggestions previously listed here, but there are potentially a lot of ways to cheat this on the clientside as well.
It is a class.
Reply With Quote
  #20  
Old 01-07-2014, 06:47 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
triggerserver() does not work inside level NPCs, you would need to use triggerAction() for this case
__________________
MEEP!
Reply With Quote
  #21  
Old 01-08-2014, 01:25 AM
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
I still don't really know what you're doing so it's hard to give advice, but if your NPCs are created via putnpc2, they do have a name, and you can trigger them via triggerServer (but you have to get the name clientside; normally it isn't available). That might be the best approach.
__________________
Reply With Quote
  #22  
Old 01-08-2014, 03:36 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 callimuc View Post
triggerserver() does not work inside level NPCs, you would need to use triggerAction() for this case
Have to fix this statement, you can use triggerServer() inside level NPCs to trigger DB NPCs or weapons (and classes being joined to those). I figured this would be the best solution if you also want to receive the onActionServerSide() inside level NPCs (or NPCs created via putNPC2()) and classes being joined to those


Quote:
Originally Posted by cbk1994 View Post
You can also do

PHP Code:
function onCreated() {
  
this.level.tapThis this;
}

function 
onPow() {
  
this.chat "ouch!";
}

//#CLIENTSIDE
function onPlayerChats() {
  
triggerServer("npc""TriggerControl""Trigger"this.level.name"tapThis""Pow");

and then in an NPC TriggerControl

PHP Code:
function onActionTrigger(levelNamenpcNamecommand) {
  
findLevel(levelName).(@ npcName).trigger(command);

Though you'd want to add some security features. Usually something like this is preferable since you never know if a trigger will be received when using x/y.
__________________
MEEP!
Reply With Quote
  #23  
Old 01-08-2014, 04:13 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Allow me to clarify exactly what I'm doing.

When the player presses 'a', the player creates an NPC that I'm using as a damage block. The NPC is functional through joining a class.

Perhaps it'd be easier to explain if I did step by step what I'm doing, so I can get some better, more specific advice.

1. Player presses 'A' and creates the "damage block" NPC.
This is the code from the Weapon
PHP Code:
function onActionServerSide(){
if (
params[0] == "dmgblock"){
 
temp.npc this.level.putNPC2(player.xplayer.y"");
 
temp.npc.join("damageblock");
 }
}

//#CLIENTSIDE
function onKeyPressed(codekey){
 if (
key == "c"){
  
player.chat "Placed!";
   
triggerserver("weapon"this.name"dmgblock");
   }
  } 
I realize the placement with the x and y is off and the player will collide instantly within placing. Ignore that.

2. The NPC preforms it's function, then deletes
This is where I'm Having issues. I need the block to destroy serverside.
This is the script from the CLASS it joined

PHP Code:
function onActionServerside(){
 if (
params[0] == "destroy"){
  
destroy();
  }
  }

//#CLIENTSIDE
function onCreated(){
 
dontblock();
 
setImg("block.png");
 
onTimeOut();
 
scheduleEvent(1"onDestroy");
}


function 
onTimeOut(){
 if (
player.x in |this.xthis.2| && player.y in |this.ythis.2|) { 
 
player.chat "HIT";}
 
//Trigger Actions in the player to make him lose HP and Whatever else
 
setTimer(0.05);
}

function 
onDestroy(){
 
triggerAction("npc"this.name"destroy");

Reply With Quote
  #24  
Old 01-08-2014, 04:58 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Consider this example:
PHP Code:
function onCreated() {
  
setshape(1,32,32);
}
function 
onActionTest() {
  
this.chat random(0,100);
}

//#CLIENTSIDE

function onCreated() {
  
setTimer(0.05);
}
function 
onTimeout() {
  
triggeraction(this.x,this.y,"test");
  
setTimer(1);

__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #25  
Old 01-08-2014, 05:04 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
Weapon script:
changed your this.level.putNPC2(...) to player.level.putNPC2(...), this. would refer to the weapon while player. refers to the player)

PHP Code:
function onActionServerSide(){
  if (
params[0] == "dmgblock"){
    
temp.npc player.level.putNPC2(player.xplayer.y""); //should be player.level instead of this.level
    
temp.npc.join("damageblock");
  }
}

//#CLIENTSIDE
function onKeyPressed(codekey){
  if (
key == "c"){
    
player.chat "Placed!";
    
triggerserver("weapon"this.name"dmgblock");
  }


Class script:
removed your dontBlock() as it needs to be a blocking NPC I believe
fixed your triggerAction()
and other stuff
PHP Code:
function onCreated() {
    
//1=blocking, 32=width in pixel, 32=height in pixel
  
setshape(13232);
}

function 
onActionDestroyBlock() {
  
this.destroy();
}

//#CLIENTSIDE
function onCreated() {
  
setshape(13232);
  
this.setImg("block.png");
  
onTimeOut();
}


function 
onTimeOut(){
    
//if player is within the square, trigger the actions
  
if (player.x in |this.xthis.2| && player.y in |this.ythis.2|) { 
    
player.chat "HIT";
      
//stop the script and call the 'onDestroyObject()' function
    
return onDestroyObject();
  }
    
//keep running the script as the player hasnt been inside the block range yet
  
setTimer(0.05);
}

function 
onDestroyObject() {
    
//x, y, onAction...., parameters
  
triggerAction(this.xthis.y"DestroyBlock"NULL);

__________________
MEEP!
Reply With Quote
  #26  
Old 01-08-2014, 05:21 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
[QUOTE=BlueMelon;1724944]Consider this example:


Thanks for the tip. Here's what I got

PHP Code:
function onCreated() {
  
setshape(1,32,32);
  
setImg("block.png");
}

function 
onActionTest(){
  
destroy();
  }

//#CLIENTSIDE
function onCreated(){
 
dontblock();
 
setTimer(1);
  if (
player.x in |this.xthis.2| && player.y in |this.ythis.2|) { 
  
player.chat "HIT";} 
}


function 
onTimeOut(){
 
triggeraction(this.x,this.y,"Test");


PROBLEM:
It sometimes works, and sometimes doesn't. It seems to only destroy half the time... Anything I can modify to make it more reliable?
Reply With Quote
  #27  
Old 01-08-2014, 06:30 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Take a look at what you posted, and what callimuc and I have posted.

You are checking the collision when the npc is created. Meaning it is comparing the coordinates once... this is not what you want.
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #28  
Old 01-08-2014, 06:33 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 i8bit View Post
PROBLEM:
It sometimes works, and sometimes doesn't. It seems to only destroy half the time... Anything I can modify to make it more reliable?
you need to put the players location check into the loop, check my example. else it will only work when the block is being placed but it never checks back again.
__________________
MEEP!
Reply With Quote
  #29  
Old 01-08-2014, 09:07 PM
Torankusu Torankusu is offline
Elite Member
Torankusu's Avatar
Join Date: Jun 2001
Posts: 10,065
Torankusu is a jewel in the roughTorankusu is a jewel in the rough
What they said
Plus, its also probably noteworthy to make sure you use setTimer (0.05 or however long...) in the onTimeout function to continue the loop -- you don't have it this way in your example.

Also, not necessary, but if you wanted to start the loop as immediately as it was created just call onTimeout (); in the on created function.

edit: sorry, missed it on my phone.
callimuc's example is spot on -- disregard my post if you follow his examples -- or just take them as an explanation for what he did. :]
__________________
Quote:
Originally posted by Spark910
Think befreo you type.

Last edited by Torankusu; 01-09-2014 at 02:02 AM..
Reply With Quote
  #30  
Old 01-09-2014, 04:36 AM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
I wanna thank everyone for all the advice! I have been really learning a lot!
So far I have it running correct with the tests I have put it through. But if I run in to any trouble I will be sure to add on to this thread with my questions.
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 01:51 PM.


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