Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Need help with a custom movement script. (https://forums.graalonline.com/forums/showthread.php?t=134259339)

Jiroxys7 05-29-2010 08:46 PM

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]};



cbk1994 05-29-2010 09:10 PM

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]}; 



DustyPorViva 05-29-2010 11:31 PM

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).

adam 05-29-2010 11:45 PM

Quote:

Originally Posted by DustyPorViva (Post 1579308)
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.

DustyPorViva 05-30-2010 12:04 AM

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;




All times are GMT +2. The time now is 10:18 AM.

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