View Single Post
  #12  
Old 01-05-2014, 11:32 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
Think you could give me an example/scenario?
The simple solution is just take Starfire's code and modify it to send a trigger...

PHP Code:
//#CLIENTSIDE
function onCreated() { 
  
setImg("block.png"); 
  
onTimeout();  // probably better than setting a timer here as you might not want to wait a second before checking 


function 
onTimeout() { 
  
// assuming that your block's dimensions are 2x2 
  
if (player.x in |this.xthis.2| && player.y in |this.ythis.2|) { 
    
triggerServer("npc""HealthSystem""hitByBlock");
    return 
setTimer(1); // to avoid sending 20 triggers per second
  
}
  
  
setTimer(.05); // or higher if it doesn't need to be so accurate 

and then in a DB NPC HealthSystem...

PHP Code:
function onActionServerSide(temp.cmd) {
  if (
temp.cmd == "hitByBlock") {
    echo(
player.niceName() @ " was hit by a block.");
    
player.hit(1); // or whatever
  
}

You could also send a point trigger (but those can be unreliable) or do this a bunch of other ways. There are some neat tricks you can use to do this more efficiently but I'd need to know more about what you're trying to do to know if they'd work here.

Note that the above makes it possible for cheating players to not be hit by the block, so if you care about that, you should do everything serverside.
__________________
Reply With Quote