Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   playertouchsme problem (https://forums.graalonline.com/forums/showthread.php?t=81613)

Understood 09-02-2008 02:35 AM

playertouchsme problem
 
I'm working on an event where basically you're falling down a shaft and you have to dodge these spikes that randomly place themselves while you fall...However, I used onPlayerTouchsme() without knowing the player had to be facing the object z.z

The player needs to die when touching the spike, regardless of their direction! Is there anything I can do to get around this?

PHP Code:

function onPlayerTouchsme()
{
  if (
player.< (this.1.5))
  {
    
this.killPlayer();
  }



DustyPorViva 09-02-2008 02:44 AM

PlayerTouchesme actually initiates when the player actually touches the NPC. And that only happens when the player is moving(pressing a key) and connects... not when the player and object hit each other.

You'll have to run a timeout and check for when the player is in the proper coordinates.

Demisis_P2P 09-02-2008 02:57 AM

SOUNDS COOOOL.

I don't know the syntax for GS2, but you could use something like
playerx in |x,x2| && playery in |y,y2|

cbk1994 09-02-2008 03:36 AM

I would probably do something like

PHP Code:

function onCreated()
{
  
onTimeOut();
}
function 
onPlayerEnters()
{
  
onCreated();
}
function 
onTimeOut()
{
  if ( 
players.size() <= )
  {
    return;
  }
  
  
temp.pl findNearestPlayerthis.xthis.);
  
  if ( 
pl.x in this.2this.| && pl.y in this.2this.)
  {
    
pl.attack();
  }
  
  
setTimer.3 );


You could also have a system weapon like this:
PHP Code:

//#CLIENTSIDE
function onCreated()
{
  
setTimer0.05 );
}
function 
onTimeOut()
{
  
temp.ns findareanpcsplayer.1player.12);
  
  for ( 
temp.npc ns )
  {
    if ( 
npc.isSpike )
    {
      
player.attack();
    }
  }
  
setTimer0.05 );


and in the spike

PHP Code:

function onCreated()
{
  
this.isSpike true;
}
function 
onPlayerEnters()
{
  
player.addWeapon"-SpikeDetector" );
  
onCreated();



[email protected] 09-02-2008 08:12 AM

for Era?

[The Class]
HTML Code:

function onCreated() {
  this.setShape(1, 32, 32);
}

function onActionDetect() {
  //Public function for doing damage
}
//#CLIENTSIDE
function onPlayerEnters() {
  this.x = random(this.x - 10, this.x + 10); //Make it random...
  setTimer(0.05);
}

function onTimeout() {
  if (player.x in |this.x, this.x + 32| && player.y in |this.y, this.y + 32|) {
    if (this.wait =< 0) {
      triggeraction(this.x, this.y, "Detect", "");
      this.wait = 4;
    }
  }
  if (this.wait >
0) this.wait -= 0.05;
  setTimer(0.05);
}


DrakilorP2P 09-02-2008 02:53 PM

Try not to make anyone angry with poor collision detection. So far everyone in this thread have suggested a rectangle, which might now make a spike justice.

Kristi 09-02-2008 04:49 PM

Umm... serverside code for this Sid? Terrible, and CBK might be complicating things too much.

Logical steps people
Things we need to do:
- Init things
- timeout start
- Spawn a spike?
--- Random check for spike
--- Check to see if the spawning rate should change
- update spike positions
- check for player collisions
--- do what happens when player collides.
- timeout

PHP Code:

//#CLIENTSIDE

// ================ Events ===================

function onCreated() {
  
init();
  
onTimeout();
}

//====================

function onTimeout() {
  if(
checkSpawnSpike(this.spawnRate)) {
    
this.spikes.add(spawnSpike());
  }
  for (
temp.sthis.spikes) {
    
temp.s.updateSpikePos();
    if(
temp.s.checkPlayerCollision()) {
      
doPlayerDamage();
    }
  }
  
setTimer(.05);
}

// ============= ! End Events ====================

// ========== User Defined Functions ===============

function init() {
  
// init values here
  // for example: the starting rate of spikes
}

//=====================

function checkSpawnRate() {
  
// return true if should spawn a spike
  // false is not
  // (maybe use random? :D)
}

//=======================

function spawnSpike() {
  
// Return an object with the spike's properties & functions
  // Functions include 
  // updateSpikePos() 
  //   - change the spike's coordinates
  //   - change where the spike visually is.
  // checkPlayerCollision()
  //   - most likely a check to see if an isosceles triangle (spike) 
  //     is colliding with a rectangle (player)
  //     return true if is and false otherwise
}

//====================

function doPlayerDamage() {
  
// What happens when a player actually gets hit.
}

// ========== ! User Defined Functions ============= 


Inverness 09-02-2008 10:39 PM

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.spikechance 10// 10 percent
  
this.spikebox = {<x>, <y>, <width>, <height>}; //area to spawn spikes
  
this.settimer(0.05);
}
function 
onTimeout() {
  if (
this.shouldspawnspike()) {
    
this.spikes.add(this.spawnspike());
  }
  for (
temp.ithis.spikes) {
    
this.updatespike(temp.i);
    if (
this.checkspike(temp.i)) {
      
this.damageplayer();
    }
  }
  
this.settimer(0.05);
}
function 
shouldspawnspike() {
  return 
random(099) < this.spikechance;
}
function 
spawnspike() {
  
temp.spike = new TStaticVar();
  
temp.spike.= <random x>;
  
temp.spike.= <random y>;
  
// x and y should be in this.spikebox
  
return temp.spike;
}
function 
updatespike(spike) {
  
temp.spikeindex this.spikes.index(temp.spike);
  
with (findimg(200 temp.spikeindex)) {
    
this.temp.spike.x;
    
this.temp.spike.y;
    
// blah
  
}
}
function 
checkspike(spike) {
  
// Collision check
}
function 
damageplayer() {
  
// o.o


I like my styling better. :)

And that script would fill up the box, probably not what you want.

*Bored*

[email protected] 09-05-2008 08:54 AM

ahh, using showimg, good idea


All times are GMT +2. The time now is 06:47 PM.

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