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 08-10-2014, 05:13 PM
Joshua_P2P Joshua_P2P is offline
Graal Developer
Joshua_P2P's Avatar
Join Date: Dec 2012
Posts: 74
Joshua_P2P is on a distinguished road
Post 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
__________________
Keeping it real in Graal since 2010
Reply With Quote
  #2  
Old 08-12-2014, 03:52 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
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)
__________________
MEEP!
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 03:03 PM.


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