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 12-31-2010, 07:17 AM
Twilikari Twilikari is offline
Registered User
Twilikari's Avatar
Join Date: Nov 2010
Location: America
Posts: 86
Twilikari is on a distinguished road
Boot Help

I was looking at some scripts on Testbed, because i'm attempting to learn, and the boot script(s) didn't make a bit of sense to me. If somebody could please just take it apart and explain it to me, I'd be really greatful
Reply With Quote
  #2  
Old 12-31-2010, 08:30 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
The boot script on Testbed is atrocious, not sure why it's so awful as it was much better when I first added it.

A better boot script would look like this:

PHP Code:
//#CLIENTSIDE
function onCreated() { // called when the client logs in or the script is updated 
  
this.speed 1// set the default speed to 1 


function 
onKeyPressed(codekey) { 
  if (
key == "b") {
    
// toggle boots 
    
this.on = ! this.on// sets this.on to the opposite of the current value, i.e. toggles it 
    
player.chat "Boots: " @ (this.on "On" "Off"); // ternary operator makes it easier than an if-statement, but either works 
     
    
if (this.on) { // is it on now? 
      
this.trigger("timeout"null); // start the timeout; second parameter not req'd on v6; can also use setTimer(0.05) 
    

  } 
}

function 
onTimeOut() { 
  if (! 
this.on) { // boots were turned off 
    
return; // this statement ends the function; code below is not executed 
  

   
  
// there are four directions and keydown takes 0/1/2/3 for up/left/down/right 
  // so looping through these and checking if the key is down is the easiest 
  // way to move the player if the key is pressed 
  
for (temp.key 0key 4key ++) { 
    if (
keydown(key)) { // is the key down? 
      // vecx and vecy, in a simple explanation, give the amount that the player 
      // needs to move horizontally and vertically for the given direction; 
      // multiplying this by this.speed increases the speed at which the player 
      // moves in that direction 
      
player.+= (vecx(key) * this.speed); 
      
player.+= (vecy(key) * this.speed); 
    } 
  } 
   
  
this.setTimer(0.05); 


function 
onPlayerChats() { 
  if (
player.chat.starts("/speed ")) { 
    
// substring returns the part of the string after the x character, where x 
    // is the first parameter -- in this case, it returns everything after 
    // "/speed " in the player's chat 
    
this.speed player.chat.substring(7).trim(); // trim removes spaces at the beginning and end 
    
player.chat "Speed: " this.speed// tell the player what the new speed is 
  


These are pretty heavily commented but if you have any questions I can break it down line-by-line.
__________________
Reply With Quote
  #3  
Old 12-31-2010, 07:26 PM
Twilikari Twilikari is offline
Registered User
Twilikari's Avatar
Join Date: Nov 2010
Location: America
Posts: 86
Twilikari is on a distinguished road
Thank you so much!!

Those testbed boots were terrible to understand, but I actually fully understand yours. Thankssss!
Reply With Quote
  #4  
Old 01-01-2011, 11:43 AM
PowerProNL PowerProNL is offline
Retired Zone Manager
PowerProNL's Avatar
Join Date: Feb 2008
Location: Holland
Posts: 266
PowerProNL can only hope to improve
Send a message via AIM to PowerProNL
Kentucky Friend ChrisVimes
__________________
Graal Mail: [email protected]
McPowerProNL, I'm loving it
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 09:24 PM.


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