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 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";
    
413;
    
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;
      
131;
      new 
GuiTextListCtrl("WEP_TextList6") {
        
profile GuiTextListProfile;
        
height 32;
        
horizsizing "width";
        
width 125;
      }
    }
    new 
GuiButtonCtrl("WEP_Button1") {
      
profile GuiButtonProfile;
      
text "Remove";
      
width 80;
      
5;
      
349;
    }
    new 
GuiButtonCtrl("WEP_Button2") {
      
profile GuiButtonProfile;
      
text "Add";
      
width 80;
      
5;
      
314;
    }
    new 
GuiTextEditCtrl("WEP_TextEdit1") {
      
profile GuiTextEditProfile;
      
height 20;
      
width 163;
      
91;
      
319;
    }
    new 
GuiTextEditCtrl("WEP_TextEdit2") {
      
profile GuiTextEditProfile;
      
height 20;
      
width 163;
      
91;
      
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 0temp.weps player.weapons.size(); temp.weps++) {
    
WEP_TextList5.addrow(temp.wepsplayer.weapons[temp.weps].name);
  }
}

function 
UpdateList2() {
  
WEP_TextList6.clearrows();
  for (
temp.weps 0temp.weps player.weapons.size(); temp.weps++) {
    if (!(
player.weapons[(@temp.weps)].name.starts("-"))) {
      
WEP_TextList6.addrow(temp.wepsplayer.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:	330
Size:	81.9 KB
ID:	53460  
__________________
Reply With Quote
  #2  
Old 08-17-2011, 12:10 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Do you want this to be based on GUI controls? I find commands to be more handy. I got !addw and !rmvw to add/remove weapon NPCs on the fly. Works like a charm.
Reply With Quote
  #3  
Old 08-17-2011, 12:14 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
Quote:
Originally Posted by Crow View Post
Do you want this to be based on GUI controls? I find commands to be more handy. I got !addw and !rmvw to add/remove weapon NPCs on the fly. Works like a charm.
I normally use GUI's to make things look nicer, but yeah I could do that easily and it does sound more practical.
Thanks!
__________________

Last edited by Emera; 08-17-2011 at 12:48 AM..
Reply With Quote
  #4  
Old 08-17-2011, 12:21 AM
Maelstrom002 Maelstrom002 is offline
Registered User
Join Date: Aug 2011
Location: Canada, MB
Posts: 5
Maelstrom002 is on a distinguished road
I would take the entire GUI Creation and move it into it's own function, versus having it in onCreated(), so that if you ever update the weapon, everyone who has it won't have it pop open on them!

Also, instead of using the two textEditCtrls, you could simply replace that with the text of your TextList, so you don't need to type in the name of the weapon, just select it from the list and hit add/remove.
Lastly I would say to add braces in your top set of lines, for your :


PHP Code:
function onActionServerSide() 

  if (
params[0] == "addweaponwep")
  {
    
addweapon(params[1]); //Add the weapon.  
  
}
  else if (
params[0] == "takeweaponwep")
  {
    
removeweapon(params[1]); //Take the weapon.
  
}


It's really a personal preference, but I think it's easier to read/update in the future
for others. Perhaps even come up with more unique/descriptive names for your ctrls
so down the road you can just look at it and see what they correspond to!
Reply With Quote
  #5  
Old 08-17-2011, 12:48 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
Quote:
lso, instead of using the two textEditCtrls, you could simply replace that with the text of your TextList, so you don't need to type in the name of the weapon, just select it from the list and hit add/remove.
Yeah lol I noticed that AFTER I put down the 2 texteditctrls but I never got around to removing them.
Quote:
Lastly I would say to add braces in your top set of lines.
I didn't know they where needed, but if you say so. I thought it makes it look neater that way.
Quote:
Perhaps even come up with more unique/descriptive names for your ctrls
so down the road you can just look at it and see what they correspond to!
Yeah I need to be a bit more "Creative" with my names. Thanks for helping me out!
__________________
Reply With Quote
  #6  
Old 08-17-2011, 01:00 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
I decided to take on board what crow said about how using the players chat is more efficient for adding weapons. I have decided to make a quick weapon adder using !add and !rem. Thank you crow <3
PHP Code:
function onActionServerSide() {
  if (
params[0] == "scriptwepadd") { //Adds the specified weapon
    
addweapon(params[1]);
  }
  if (
params[0] == "scriptwepremove") { //Removes the specified weapon
    
removeweapon(params[1]);
  }
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("!add ")) {
    
triggerserver("gui"this.name"scriptwepadd"player.chat.substring(5));
  }
  if (
player.chat.starts("!rem ")) {
    
triggerserver("gui"this.name"scriptwepremove"player.chat.substring(5));
  }

Obviously, if I wanted to I could branch off of that and expand it to add weapons to all players, certain players, a specified player etc.

Styled using FowlPlay4's GS2 Beautifier
__________________
Reply With Quote
  #7  
Old 08-17-2011, 01:04 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
one of the first things you should do is verify who is actually sending this trigger to the server since it's incredibly insecure otherwise

and then while you're at it you should prefix addweapon and removeweapon with the proper object (player)
Reply With Quote
  #8  
Old 08-17-2011, 01:07 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
Quote:
Originally Posted by Mark Sir Link View Post
one of the first things you should do is verify who is actually sending this trigger to the server since it's incredibly insecure otherwise

and then while you're at it you should prefix addweapon and removeweapon with the proper object (player)
Don't understand how to verify that. But here is it prefixed...
PHP Code:
function onActionServerSide() {
  if (
params[0] == "scriptwepadd") { //Adds the specified weapon
    
player.addweapon(params[1]); //Prefixed player.addweapon
  
}
  if (
params[0] == "scriptwepremove") { //Removes the specified weapon
    
player.removeweapon(params[1]); //Prefixed player.removeweapon
  
}
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("!add ")) {
    
triggerserver("gui"this.name"scriptwepadd"player.chat.substring(5));
  }
  if (
player.chat.starts("!rem ")) {
    
triggerserver("gui"this.name"scriptwepremove"player.chat.substring(5));
  }

__________________
Reply With Quote
  #9  
Old 08-17-2011, 01:10 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
A small comment on the "Chat vs. GUI" topic:

I think it's good to have both. Chat for "power players" (those who frequently), and GUI for new players or those who don't player often enough to bother remember commands.

This is mainly the approach we take on Classic. But it become more critical to properly abstract things with this approach because otherwise you'll have duplicate code lying all over the place.
Reply With Quote
  #10  
Old 08-17-2011, 01:14 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
Quote:
Originally Posted by WhiteDragon View Post
A small comment on the "Chat vs. GUI" topic:

I think it's good to have both. Chat for "power players" (those who frequently), and GUI for new players or those who don't player often enough to bother remember commands.

This is mainly the approach we take on Classic. But it become more critical to properly abstract things with this approach because otherwise you'll have duplicate code lying all over the place.
If I was to redo the GUI, not that I am going to, would it even be necessary to add the weapon list control or would I be better off without it and just have a text box with a button or two to add and delete?
__________________
Reply With Quote
  #11  
Old 08-17-2011, 02:54 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
Quote:
Originally Posted by Emera View Post
If I was to redo the GUI, not that I am going to, would it even be necessary to add the weapon list control or would I be better off without it and just have a text box with a button or two to add and delete?
Well, in this specific case just commands are probably fine -- if there is a staff member who is not a power player then you clearly have some other problems to fix first .

But in the name of theory, if this was actually a public facing weapon, then I'd say have a weapon list, since just a text box isn't particularly friendly and is pretty much the exact same thing as a normal chat command.
Reply With Quote
  #12  
Old 08-17-2011, 02:59 AM
Maelstrom002 Maelstrom002 is offline
Registered User
Join Date: Aug 2011
Location: Canada, MB
Posts: 5
Maelstrom002 is on a distinguished road
I think the best option would be to incorporate both within the same weapon. Allow players to be able to access the GUI if need-be to see a list of what they could add to themselves, or what they already have.
Then also allow for the chat commands for those who know what they have/need and can quickly add/remove things without having to navigate a GUI.
Reply With Quote
  #13  
Old 08-17-2011, 03:33 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
in the onActionServerside portion of the script you should be verifying that the player who sent the trigger is actually someone you expect it to be, IE

if(player.account in serveroptions.staff.tokenize(","))
Reply With Quote
  #14  
Old 08-17-2011, 11:40 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
Ah okiedokie thanks for that.
__________________
Reply With Quote
  #15  
Old 08-17-2011, 01:16 PM
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
Quote:
Originally Posted by Mark Sir Link View Post
in the onActionServerside portion of the script you should be verifying that the player who sent the trigger is actually someone you expect it to be, IE

if(player.account in serveroptions.staff.tokenize(","))
You should check player.communityname, not player.account, since for some reason Stefan decided that the new accounts have to have their community name in the staff list.
__________________
Reply With Quote
  #16  
Old 08-17-2011, 01:52 PM
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
Quote:
Originally Posted by cbk1994 View Post
You should check player.communityname, not player.account, since for some reason Stefan decided that the new accounts have to have their community name in the staff list.
Would it be practical to check for both?
__________________
Reply With Quote
  #17  
Old 08-17-2011, 03:37 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
Quote:
Originally Posted by Emera View Post
Would it be practical to check for both?
maybe since servers mostly still have the accounts.
PHP Code:
if(player.account in serveroptions.staff.tokenize(",") || player.communityname in serveroptions.staff.tokenize(",")) 
__________________
MEEP!
Reply With Quote
  #18  
Old 08-17-2011, 07:19 PM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by callimuc View Post
maybe since servers mostly still have the accounts.
PHP Code:
if(player.account in serveroptions.staff.tokenize(",") || player.communityname in serveroptions.staff.tokenize(",")) 
the only time a communityname wouldn't return the proper value (I think this is still the case) is if a new Graal####### account hasn't set a community name.

I guess you could do

if( ((player.communityname.length() > 0) ? player.communityname : player.account) in severoptions.staff.tokenize(","))

to prevent incorrectly formatted staff lists that might have an empty value somewhere from returning true for players that haven't set their community name.
Reply With Quote
  #19  
Old 08-17-2011, 09:40 PM
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
Quote:
Originally Posted by Emera View Post
Would it be practical to check for both?
There's no reason to. All you really need to check for is the community name. Players with old accounts will have their account as their community name.
__________________
Reply With Quote
  #20  
Old 08-17-2011, 09:53 PM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by cbk1994 View Post
There's no reason to. All you really need to check for is the community name. Players with old accounts will have their account as their community name.
on Unholy Nation I was checking exclusively for community names and stumbled into the same problem I posted about with an improperly formatted staff list.

Granted, I couldn't actually find any instances of an empty entry in the array but it was still returning true when I checked player.communityname in the array.

each array member -

PHP Code:
[Manager]
Absolut_Crono
[Admin]
Flares
[Dev_Admin]
Mark Sir Link
KevDoh
[NAT_Admin]
[
Scripting_Team]
Toxen
Deas_Voice
devilsknite1
MysticalDragon
thatdwarf
ApothiX
Hezzy002
Switch
zeldaguardian
[Graphics]
Blazeik
JeffNightVale
[Levels_Admin]
shyguy2
[Levels_Team]
javierkid
Dr_Doctor
Hostility
27Chris1
snoop413
HolySerenity
[FAQ]
Kamakaze
Samurai_X2689
Dread
ranmalrac1
Hosaun
[Gani_Team]
dark_mater_s
[Events_Team]
Jello
Elite3
four_swords
Unknown_Prophecy
KaidaChan
warcraft1111
maxi123
GracefulCharity
BrutaL
Timez
Battousai90290
larenaz19
babyx
[Graal_Police]
CertifiedGangsta252
Okilian
dubby230
nightslayer317
Hiro
taylor
ssgohan87
MooseInATree
weeway
[Developer]
Bane
SwimChao
Gamerkid7
[SFX]
[
Uploader]
Door
[Unholy_Radio]
[
The_Man]
_Zelph
[ET_Dev_Admin]
Starfire2001
[ET_Dev]
Akios
[Global]
Skyld
[ENDSTAFF
Reply With Quote
  #21  
Old 08-17-2011, 10:19 PM
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
Quote:
Originally Posted by Mark Sir Link View Post
on Unholy Nation I was checking exclusively for community names and stumbled into the same problem I posted about with an improperly formatted staff list.

Granted, I couldn't actually find any instances of an empty entry in the array but it was still returning true when I checked player.communityname in the array.
Good point. I wish Stefan would just fix community names.
__________________
Reply With Quote
  #22  
Old 08-17-2011, 11:23 PM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by cbk1994 View Post
Good point. I wish Stefan would just fix community names.
I guess servers could try to force it on players by disconnecting them if their community name is null and using the shared admin function thing but I doubt Stefan would approve or appreciate it.

I didn't even think it would be problematic initially until all of a sudden I see RC get flooded with players warning each other.
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 02:30 AM.


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