Thread: Weapon Control
View Single Post
  #1  
Old 08-17-2011, 12:03 AM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Weapon Control

I keep getting very annoyed of adding the same line to add my weapons at the top of my scripts.
PHP Code:
findplayer("Graal772919").addweapon(this.name); 
So I decided to knock me up a GUI to help me along. All it does is add and remove weapons from Your player only. I was wondering, since it does what it needs to do, and it helps me along, is there any way you guys can help me improve, shorten or simplify the script?

The Script (-System/WepCtrl)
PHP Code:
/* Uses two lists to show two categories of weapons. 
List one shows all weapons. Hidden (-Weapon/Name) and non-hidden (Weapon/Name)
List two shows only the non-hidden weapons (Weapon/Name)
To add or remove the weapons;
Type the name of the weapon into the add or remove box and hit the button.
Tap the button twice to update the list.
Opening the GUI is easy. Just say "/wepcontrol"
*/
function onActionServerSide() {
  if (
params[0] == "addweaponwep") addweapon(params[1]); //Add the weapon.
  
if (params[0] == "takeweaponwep") removeweapon(params[1]); //Take the weapon.
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat == "/wepcontrol") {
    
player.chat = "";
    
WEP_Window1.visible = true; //Open the GUI
  
}
}

function 
onCreated() {
  new 
GuiWindowCtrl("WEP_Window1") {
    
profile = GuiWindowProfile;
    
clientrelative = true;
    
clientextent = "260,385";
    
canmaximize = false;
    
canmove = true;
    
canresize = true;
    
closequery = false;
    
destroyonhide = false;
    
text = "WEP - Control";
    
x = 413;
    
y = 73;
    new 
GuiScrollCtrl("WEP_TextList5_Scroll") {
      
profile = GuiScrollProfile;
      
height = 307;
      
hscrollbar = "alwaysOff";
      
vscrollbar = "dynamic";
      
width = 128;
      new 
GuiTextListCtrl("WEP_TextList5") {
        
profile = GuiTextListProfile;
        
height = 32;
        
horizsizing = "width";
        
width = 124;
      }
    }
    new 
GuiScrollCtrl("WEP_TextList6_Scroll") {
      
profile = GuiScrollProfile;
      
height = 307;
      
hscrollbar = "alwaysOff";
      
vscrollbar = "dynamic";
      
width = 129;
      
x = 131;
      new 
GuiTextListCtrl("WEP_TextList6") {
        
profile = GuiTextListProfile;
        
height = 32;
        
horizsizing = "width";
        
width = 125;
      }
    }
    new 
GuiButtonCtrl("WEP_Button1") {
      
profile = GuiButtonProfile;
      
text = "Remove";
      
width = 80;
      
x = 5;
      
y = 349;
    }
    new 
GuiButtonCtrl("WEP_Button2") {
      
profile = GuiButtonProfile;
      
text = "Add";
      
width = 80;
      
x = 5;
      
y = 314;
    }
    new 
GuiTextEditCtrl("WEP_TextEdit1") {
      
profile = GuiTextEditProfile;
      
height = 20;
      
width = 163;
      
x = 91;
      
y = 319;
    }
    new 
GuiTextEditCtrl("WEP_TextEdit2") {
      
profile = GuiTextEditProfile;
      
height = 20;
      
width = 163;
      
x = 91;
      
y = 354;
    }
  }
}

function 
WEP_Button1.onAction() { //Hit once to taje weapon, hit twice to update list.
  // Button "Remove" has been pressed
  
UpdateList1(); //Updates List
  
UpdateList2();
  
removechat(); //Sets Chat
  
triggerserver("gui", this.name, "takeweaponwep", WEP_TextEdit2.text);
}

function 
WEP_Button2.onAction() { //Hit once to add weapon, hit twice to update list.
  // Button "Add" has been pressed
  
UpdateList1(); //Updates List
  
UpdateList2();
  
addchat(); //Sets Chat
  
triggerserver("gui", this.name, "addweaponwep", WEP_TextEdit1.text);
}

function 
UpdateList1() {
  
WEP_TextList5.clearrows();
  for (
temp.weps = 0; temp.weps < player.weapons.size(); temp.weps++) {
    
WEP_TextList5.addrow(temp.weps, player.weapons[temp.weps].name);
  }
}

function 
UpdateList2() {
  
WEP_TextList6.clearrows();
  for (
temp.weps = 0; temp.weps < player.weapons.size(); temp.weps++) {
    if (!(
player.weapons[(@temp.weps)].name.starts("-"))) {
      
WEP_TextList6.addrow(temp.weps, player.weapons[temp.weps].name);
    }
  }
}

function 
RemoveChat() {
  if (!(
WEP_TextEdit2.text == NULL)) player.chat = "Removed: " @ WEP_TextEdit2.text; //Sets chat
}

function 
AddChat() {
  if (!(
WEP_TextEdit1.text == NULL)) player.chat = "Added: " @ WEP_TextEdit1.text; //Sets Chat
} 
Graal PasteBin Version

Thank you to everybody who helps me out.

Styled using FowlPlay4's GS2 Beautifier
Attached Thumbnails
Click image for larger version

Name:	WepCtrl.PNG
Views:	331
Size:	81.9 KB
ID:	53460  
__________________
Reply With Quote