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 09-02-2008, 02:35 AM
Understood Understood is offline
Registered User
Join Date: Jun 2006
Location: Orlando, FL
Posts: 120
Understood is on a distinguished road
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();
  }

Reply With Quote
  #2  
Old 09-02-2008, 02:44 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #3  
Old 09-02-2008, 02:57 AM
Demisis_P2P Demisis_P2P is offline
Kanto League Champion
Demisis_P2P's Avatar
Join Date: Jan 2005
Posts: 2,357
Demisis_P2P has much to be proud ofDemisis_P2P has much to be proud ofDemisis_P2P has much to be proud ofDemisis_P2P has much to be proud ofDemisis_P2P has much to be proud ofDemisis_P2P has much to be proud ofDemisis_P2P has much to be proud of
SOUNDS COOOOL.

I don't know the syntax for GS2, but you could use something like
playerx in |x,x2| && playery in |y,y2|
__________________
Reply With Quote
  #4  
Old 09-02-2008, 03:36 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 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();

__________________
Reply With Quote
  #5  
Old 09-02-2008, 08:12 AM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
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);
}
Reply With Quote
  #6  
Old 09-02-2008, 02:53 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
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.
Reply With Quote
  #7  
Old 09-02-2008, 04:49 PM
Kristi Kristi is offline
Bowie's Deciple
Kristi's Avatar
Join Date: Dec 2003
Location: Boston, MA
Posts: 748
Kristi has a spectacular aura aboutKristi has a spectacular aura about
Send a message via AIM to Kristi Send a message via MSN to Kristi
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 ============= 
__________________
Reply With Quote
  #8  
Old 09-02-2008, 10:39 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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*
__________________
Reply With Quote
  #9  
Old 09-05-2008, 08:54 AM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
ahh, using showimg, good idea
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:45 AM.


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