Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-16-2011, 05:02 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Here's how Zodiac's baddy movement works. It doesn't move directly to the player in one step but instead takes it in strides of 0.5 seconds of movement at max.

PHP Code:
// Removed Zodiac Specific Code
function onPlayerEnters() {
  if (!
this.on) {
    
this.on true;
    
onTimeout();
  }
}

function 
onTimeout() {
  if (
players.size() < 1) {
    
this.on false;
    return;
  }
  
chase(players[0]);
}

function 
chase(target) {
  
// Set Speed
  
temp.speed .3;
    
  
// Calculate Position in front of Target
  
temp.tpos = {target.vecx(this.dir)*2.5target.vecy(this.dir)*2.5};
  
// Calculate Distance to Target
  
temp.dist = ((temp.tpos[0] - x)^+ (temp.tpos[1] - y)^2)^.5;
  
// Calculate Steps Required 
  
temp.steps temp.dist temp.speed;
  
// Avoid Too Many Steps
  
if (temp.steps 10)
    
temp.steps 10;

  
// Calculate Angle towards Target
  // Random helps prevent clumping of npcs
  
temp.angle getangle(temp.tpos[0] - xtemp.tpos[1] - y) + random(-0.2,0.2);
  
// Calculate the Delta
  
temp.dx cos(temp.angle) * temp.speed;
  
temp.dy = -sin(temp.angle) * temp.speed;

  
setcharani("walk"this.attr[2]);
  
move(temp.dx temp.stepstemp.dy temp.stepsint(temp.steps) * .058);

  
setTimer(int(temp.steps) * .05);
}

function 
onMovementFinished() {
  
setcharani("idle""");

Sure it still allows baddies to walk over walls but it's an even bigger issue when players can glitch them into corners and abuse the situation.
__________________
Quote:
Reply With Quote
  #2  
Old 04-16-2011, 05:25 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Quote:
Originally Posted by fowlplay4 View Post
Here's how Zodiac's baddy movement works....
Ok but I want the rat to run the race fairly. This "baddy" wouldn't be used for fighting. I have programmed in an area, and I want the npc to "wander" into that area through the maze. It would be like an AI for the NPC. So say the NPC is a farm hand and works in the field. I want the NPC to walk to work without being caught at the gate, and then be able to get back home after quitting time without planning its every move. This way it would be easy to implement a "living" server.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #3  
Old 04-16-2011, 05:54 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by kingcj View Post
Ok but I want the rat to run the race fairly. This "baddy" wouldn't be used for fighting. I have programmed in an area, and I want the npc to "wander" into that area through the maze. It would be like an AI for the NPC. So say the NPC is a farm hand and works in the field. I want the NPC to walk to work without being caught at the gate, and then be able to get back home after quitting time without planning its every move. This way it would be easy to implement a "living" server.
Different scenarios have different solutions.

Also I should note that you're venturing into an area that's more 'theory' than language-specific and your ability will require you to convert that theory into actual script.
__________________
Quote:
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 09:30 AM.


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