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 05-29-2010, 08:46 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Need help with a custom movement script.

Alright, so i found a script dusty made to build off of for my custom movement script. I've been trying to get it so that when you press S, the custom sword script runs (not shown in the example). That part, I pretty much know how to do. but the problem is that the client.mode="idle"; is pretty much taking priority over everything, and i cant seem to figure out a way around this. i need it so when you press S and the attack gani begins, the script waits until the gani ends (perhaps with a timer) before it starts looping that part of the script again. the closest i got this to working was a torn-apart, messy script that almost did everything i wanted it to, except the "for (k=0;k<4;k++) {
if (keydown(k)) { " part was always returning 4. or however that works. So i figured i'd get a fresh start with this question rather than trying to deal with the headache of a script i ended up with last time. Though if you guys think it would be better if i posted the other script instead, i could do that.

PHP Code:
// NPC made by Dusty
function onActionServerside() {
  if (
params[0]=="setspeed"clientr.speed=params[1];
}
//#CLIENTSIDE
function onCreated() {
  
this.chairtiles={
    
0x2A9,0x2AA,
    
0x2B9,0x2BA,
    
0xF37,0xF38,0xF39,
    
0xF47,0xF48,0xF49,
    
0x676,0x677,0x678,
    
0x686,0x687,0x688
  
};

  
triggerserver("gui",name,"setspeed",speed);
  
disabledefmovement();

  
onTimeout();
}

function 
onTimeout() {
  
client.mode="idle"//<=== The problem?
  
for (k=0;k<4;k++) {
    if (
keydown(k)) {
      
client.mode="walk";
      
player.dir=k;
      
temp.blocked=checkwall();
      if (
blocked[0]==0) {
        
player.x+=vecx(k)*clientr.speed;
        
player.y+=vecy(k)*clientr.speed;
      } else if (
blocked[1]==&& blocked[2]==0) { 
        
player.x-=vecx((k+1)%2)*(1/16);
        
player.y-=vecy((k+1)%2)*(1/16);
      } else if (
blocked[1]==&& blocked[2]==1) {
        
player.x+=vecx((k+1)%2)*(1/16);
        
player.y+=vecy((k+1)%2)*(1/16);
      }
    }
  }
  if (
onwater(player.x+1.5,player.y+2)) client.mode="swim";
  if (
tiles[player.x+1.5,player.y+1.75in this.chairtilesclient.mode="sit";
  
setani(client.mode,null);
  
  
temp.speedmod = (client.stats2[10]/16);
  
  if(
client.mode="swim"){
  
temp.speed 3/16  temp.speedmod temp.speedmodwater;
  
triggerserver("gui",name,"setspeed",speed);}
  else{
  
temp.speed 6/16 temp.speedmod temp.speedmodland;
  
triggerserver("gui",name,"setspeed",speed);}
  
  
  
  
timeout=0.05;
}

function 
checkwall() {
  
temp.blocked=new[2];
  for (
w=0;w<1.5;w++) {
    for (
i=0;i<(clientr.speed>0?clientr.speed:1/16);i+=1/16) {
      
temp.checkx=((player.x+0.5+abs(vecx(k))-vecx((k+1)%2)*w)+vecx(k)*(1+i))+((k in {0,2})?1/16:0);
      
temp.checky=((player.y+2-abs(vecx(k))-vecy((k+1)%2)*w)+vecy(k)*(1+i))+((k in {1,3})?1/16:0);
      
blocked[w]=onwall2(checkx,checky,((k in {0,2})?15/16:1/16),((k in {1,3})?15/16:1/16));
      if (
blocked[0]+blocked[1]>0) {
        
player.x+=(vecx(k)*i);
        
player.y+=(vecy(k)*i);
        
        break;
      }
    }
  }
  return {
blocked[0]+blocked[1],blocked[0],blocked[1]};

__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #2  
Old 05-29-2010, 09:10 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
Try changing this
PHP Code:
setani(client.mode,null); 
to this
PHP Code:
if (client.mode != "idle" || (client.mode == "idle" && ! this.hasChangedIdle)) {
  
this.hasChangedIdle = (client.mode == "idle");
  
setAni(client.modenull);

This will only change the GANI to "idle" if the player has changed their player mode since the last loop.



Also, a security note:
PHP Code:
function onActionServerside() { 
  if (
params[0]=="setspeed"clientr.speed=params[1]; 

There is no point in using clientr variables if you allow the client to send the speed they want. Triggers are pretty easy to send, and there used to be a tool around for sending fake ones (not sure if it still works). You should always validate data the client sends. Something like speed should probably be set on login.

PHP Code:
// NPC made by Dusty 
function onPlayerLogin(pl) {
  
pl.clientr.speed 1;
}
//#CLIENTSIDE 
function onCreated() { 
  
this.chairtiles={ 
    
0x2A9,0x2AA
    
0x2B9,0x2BA
    
0xF37,0xF38,0xF39
    
0xF47,0xF48,0xF49
    
0x676,0x677,0x678
    
0x686,0x687,0x688 
  
}; 

  
disabledefmovement(); 

  
onTimeout(); 


function 
onTimeout() { 
  
client.mode="idle"//<=== The problem? 
  
for (k=0;k<4;k++) { 
    if (
keydown(k)) { 
      
client.mode="walk"
      
player.dir=k
      
temp.blocked=checkwall(); 
      if (
blocked[0]==0) { 
        
player.x+=vecx(k)*clientr.speed
        
player.y+=vecy(k)*clientr.speed
      } else if (
blocked[1]==&& blocked[2]==0) {  
        
player.x-=vecx((k+1)%2)*(1/16); 
        
player.y-=vecy((k+1)%2)*(1/16); 
      } else if (
blocked[1]==&& blocked[2]==1) { 
        
player.x+=vecx((k+1)%2)*(1/16); 
        
player.y+=vecy((k+1)%2)*(1/16); 
      } 
    } 
  } 
  if (
onwater(player.x+1.5,player.y+2)) client.mode="swim"
  if (
tiles[player.x+1.5,player.y+1.75in this.chairtilesclient.mode="sit"
  
  if (
client.mode != "idle" || (client.mode == "idle" && ! this.hasChangedIdle)) { 
    
this.hasChangedIdle = (client.mode == "idle"); 
    
setAni(client.modenull); 
  }
   
  
temp.speedmod = (client.stats2[10]/16); 
   
  if(
client.mode="swim"){ 
  
temp.speed 3/16  temp.speedmod temp.speedmodwater
  
triggerserver("gui",name,"setspeed",speed);} 
  else{ 
  
temp.speed 6/16 temp.speedmod temp.speedmodland
  
triggerserver("gui",name,"setspeed",speed);} 
   
   
   
  
timeout=0.05


function 
checkwall() { 
  
temp.blocked=new[2]; 
  for (
w=0;w<1.5;w++) { 
    for (
i=0;i<(clientr.speed>0?clientr.speed:1/16);i+=1/16) { 
      
temp.checkx=((player.x+0.5+abs(vecx(k))-vecx((k+1)%2)*w)+vecx(k)*(1+i))+((k in {0,2})?1/16:0); 
      
temp.checky=((player.y+2-abs(vecx(k))-vecy((k+1)%2)*w)+vecy(k)*(1+i))+((k in {1,3})?1/16:0); 
      
blocked[w]=onwall2(checkx,checky,((k in {0,2})?15/16:1/16),((k in {1,3})?15/16:1/16)); 
      if (
blocked[0]+blocked[1]>0) { 
        
player.x+=(vecx(k)*i); 
        
player.y+=(vecy(k)*i); 
         
        break; 
      } 
    } 
  } 
  return {
blocked[0]+blocked[1],blocked[0],blocked[1]}; 

__________________
Reply With Quote
  #3  
Old 05-29-2010, 11:31 PM
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
You might want to take a look at: http://forums.graalonline.com/forums...hp?t=134258376

I fix bugs like those and explain how(albeit badly).
Reply With Quote
  #4  
Old 05-29-2010, 11:45 PM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura about
Send a message via AIM to adam
Quote:
Originally Posted by DustyPorViva View Post
You might want to take a look at: http://forums.graalonline.com/forums...hp?t=134258376

I fix bugs like those and explain how(albeit badly).
A bad explanation is far far better than no explanation, great job.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #5  
Old 05-30-2010, 12:04 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
I should note that the functionality of the default sword is a bit of a special case. You can swing it regardless of whether your player is currently frozen, but only if your gani = sword. This means the checks should go before the movement functions and the check for the player being frozen.

PHP Code:
function onTimeout() {
  
CheckSword();
  if (
player.freezetime == -1Movement();

  
setTimer(0.05);
}

function 
CheckSword() {
  
// this.keyspressed[x] would be an array that tracks the keys pressed(0-9)
  // for situations like below, or else you'd end up being able to just hold down 'S'
  // for quick and repeated swings. That would be most undesirable :P
  
if (keydown(5)) {
    if (
this.keyspressed[5] == false) {
      if (
player.freezetime == -|| player.ani == "sword") {
        
setAni("sword",null);
        
freezeplayer(.25);
      }
      
this.keyspressed[5] = true;
    }
  } else 
this.keyspressed[5] = false;

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


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