Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Script Sunday: Hotkeys (https://forums.graalonline.com/forums/showthread.php?t=134269462)

Joshua_P2P 08-10-2014 05:13 PM

Script Sunday: Hotkeys
 
Hi Everyone since Ventus (My Server) i am retiring for good this time i decided to give back to the community and help as i can so 1 or 2 Sundays a month i will donate some things from Ventus so people can use or learn from
Credit to this script goes to Emera
Setup:
1) Create a weapon (name it what you want)
2) Insert the script
3) add the weapon to you and a grey bar with boxes should appear at the bottom

Controls:
Right Click a box and your current equipped item will be added to hotkeys
Left Click a box the the item in it will be equipped
PHP Code:

//#CLIENTSIDE

function onCreated() {
  
this.keycount 10;
  if (
client.hotkeys == NULL) {
    for (
temp.0temp.this.keycounttemp.++) {
      
client.hotkeys.add("-");
    }
  }
  
drawGUI();


function 
drawGUI() {
  
Hotkeys.destroy();
  new 
GuiControl("Hotkeys") {
    
useownprofile true;
    
width =  10 + (thiso.keycount 50);
    
height 60;
    
= (screenwidth width) / 2;
    
= (screenheight height 35);

    
with (profile) {
      
modal true;
      
cankeyfocus false;
      
opaque true;
      
fillcolor = {000100};
    }
  }
  for (
temp.0thiso.keycount++) {
    
with(Hotkeys) {
      new 
GuiControl("Hotkey_" temp.i) {
        
useownprofile true;
        
width 40;
        
height 40;
        
10 + (temp.50);
        
10;

        
with(profile) {
          
opaque true;
          
border true;
          
fillcolor = {000100};
          
bordercolor = {255,255,255};
        }

        
thiso.catchevent(this"onMouseDown""onLeft");
        
thiso.catchevent(this"onRightMouseDown""onRight");

        new 
GuiBitmapCtrl("HotkeyImg_" temp.i) {
          
bitmap "";
          
width 32;
          
height 32;
          
extent = {widthheight};
          
4;
          
4;
          
//cliptobounds = true;
          
thiso.catchevent(this"onMouseDown""onLeft");
          
thiso.catchevent(this"onRightMouseDown""onRight");
        }
      }
    }
  }
  
loadKeys();
}

public function 
loadKeys() {
  for (
temp.0this.keycount++) {
    
temp.hk client.hotkeys[temp.i];
    if (
temp.hk != "-") {
      if (
findweapon(temp.hk) != NULL) {
        
temp.wepimg findweapon(temp.hk).image;
        if (
temp.wepimg == NULL) {
          
temp.wepimg "bcalarmclock.png";
        }
        (
"HotkeyImg_" temp.i).bitmap wepimg;
      } else {
        
client.hotkeys[temp.i] = "-";
        (
"HotkeyImg_" temp.i).bitmap "";
        echo(
"Removed key" SPC temp.i SPC "because didn't exist");
      }
    }
  }
}

function 
onLeft(obj) {
  
temp.hk obj.substring(obj.pos("_") + 1) + 1;
  
temp.hki temp.hk -= 1;

  if (
client.hotkeys[hki] == "-") {
    
player.chat "No hotkey stored!";
  } else {
    
player.chat "Equipped:" SPC client.hotkeys[hki];
    
selectedweapon player.weapons.index(findweapon(client.hotkeys[hki]));
  }
  
GraalControl.makefirstresponder(true);
}

function 
onRight(obj) {
  
temp.hk obj.substring(obj.pos("_") + 1) + 1;
  
temp.hki temp.hk -= 1;
  
  if (
client.hotkeys[hki] == "-") {
    
temp.wepimg findweapon(player.weapon).image;
    if (
wepimg == NULL) {
      
wepimg "bcalarmclock.png";
    }
    
client.hotkeys[hki] = player.weapon;
    (
"HotkeyImg_" hki).bitmap wepimg;
    
player.chat "Added" SPC client.hotkeys[hki];
  } else {
    
player.chat "Cleared" SPC client.hotkeys[hki];
    
client.hotkeys[hki] = "-";
    (
"HotkeyImg_" hki).bitmap "";
  }
  
GraalControl.makefirstresponder(true);


This Code is in NPC Scripting not Code Gallery, No Guarantees it's perfect

callimuc 08-12-2014 03:52 PM

stuff you could improve (yes i know you've said it's not perfect, still worth mentioning)
1. your this.keycount could be set as a const flag, as you're not altering it, just reading it.
2. might be optional, but instead of placing -'s for blank hotkey spots, i'd have just done this check
PHP Code:

if (client.hotkeys == NULLclient.hotkeys = new[this.keycount

this creates a new array with the size of this.keycount
3.
PHP Code:

temp.hk obj.substring(obj.pos("_") + 1) + 1;
temp.hki temp.hk -= 1

probably would've changed it to something like
PHP Code:

temp.hk obj.tokenize("_")[1]+1;
temp.hki temp.hk-1

for it's simplicy (ps: your temp.hki = temp.hk -= 1; reduces temp.hk by 1 again, could've left out the +1 than when creating the temp.hk)


All times are GMT +2. The time now is 06:35 AM.

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