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 06-25-2011, 07:50 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
hasweapon() not working correctly?

Alright, yesterday I ran into a problem. I learned the hard way that there's a limit to how many weapons a player has. Since my server will have a lot of classes (in the rpg sense) it will also have a lot of skills. These skills will need to be stored as weapons. So I decided that I will have a system that adds weapons if they exist in the player's skill list (stored in a variable) and delete the weapons if they are not listed in the skills variable. Right now I'm only working on the former part (adding the weaps) as I'm sure I can figure out the latter part on my own for the most part.

Anyways, the problem here is that hasweapon() always returns false, I've returned to a previous thread that I posted and tried the "player.hasWeapon()" that was posted there, but since hasWeapon is not the same as hasweapon, it didn't work either. (on a side note, i've also tried player.hasweapon() but that's apparently not a valid form of the command)

Here's the script:
PHP Code:
// Scripted by Ryu (Away)
function onActionServerSide(cmdacctweapstate){  
  if(
cmd == "UpdatedWeapons" && timeout <= 0){
    
with(acct){
      if(
state == "forced"){setTimer(0);} //Allows a manual command by the player to bypass the timeout delay.
      
player.addweapon(weap); 
      
onCheckResult(weap); //Check if the weapon was added and report the results.
    
}
  }
}

function 
onCheckResult(weap){
  if(
timeout <= 0){
    if(!
hasweapon(weap)){
      
player.chat "Failed to get" SPC weap;
      
sendtorc(acct SPC "failed to receive weapon '" weap "' from the Skill GUI.");
      
setTimer(60); //Create a delay to prevent spam.
    
}
    else{
      
player.chat "Got" SPC weap;
      
sendtorc(acct SPC "has received the weapon '" weap "' from the Skill GUI.");
    }
  }
}



//#CLIENTSIDE
function onCreated(){
  
onTimeout();
}

function 
onTimeout(){
  
onUpdateList();
  
onCheckWeapons();
  
setTimer(0.05);
}

function 
onCheckWeapons(state){//Make sure the player has a weapon for each of their skills.
  
for(i=0;i<client.skills.size();i++){
    if(! 
hasweapon("-Skills/" client.skills[i])){   
      
triggerserver("gui",this.name,"UpdatedWeapons",player.account"-Skills/" client.skills[i], state);
    }
  }
}

function 
onPlayerChats(){
  if(
player.chat == "/check:weapons"){
    
onCheckWeapons("forced");
  }
}

function 
onKeyPressed(){
if (
keydown2(keycode(e),true)) {
    
MyGUI_SkillGUI_Window1.destroy();
    
onLoadGUI();
  }
}

function 
onLoadGUI() {
  new 
GuiWindowCtrl("MyGUI_SkillGUI_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "320,109";

    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide true;
    
text "Skills:";
    
575;
    
487;

    new 
GuiScrollCtrl("MyGUI_SkillGUI_MultiLine1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 100;
      
hscrollbar "dynamic";
      
vscrollbar "dynamic";
      
width 183;
      
130;
      
5;

      new 
GuiMLTextCtrl("MyGUI_SkillGUI_MultiLine1") {
        
profile GuiBlueMLTextProfile;
        
height 32;
        
horizsizing "width";
        
text "Loading...";
        
width 158;
      }
    }
    new 
GuiScrollCtrl("MyGUI_SkillGUI_TextList1_Scroll") {
      
profile GuiBlueScrollProfile;
      
height 100;
      
hscrollbar "alwaysOff";
      
vscrollbar "dynamic";
      
width 120;
      
5;
      
5;

      new 
GuiTextListCtrl("MyGUI_SkillGUI_TextList1") {
        
profile GuiBlueTextListProfile;
        
height 32;
        
horizsizing "width";
        
width 116;
        
clearrows();
        for(
i=0;i<client.skills.size();i++){
          
addrow(i,client.skills[i]);
        }
      }
    }
  }
}

function 
MyGUI_SkillGUI_TextList1.onSelect(){
  
this.data this.sname this.basic this.description NULL;
  
this.data findweapon("-Skills/" params[1]).onGetData();
  
this.sname params[1SPC "(" this.data[0] @ ")";
  if(
this.data[2] == "N/A" && this.data[3] == "N/A" && this.data[4] == "N/A" && this.data[5] == "N/A"){
    
this.basic "Element:" SPC this.data[1]; 
  }
  elseif(
this.data[2] == "N/A" && this.data[3] == "N/A"){
    
this.basic "Element:" SPC this.data[1NL 
               
"Magic:"this.data[4SPC "Mana:" this.data[5];
  }
  elseif(
this.data[4] == "N/A" && this.data[5] == "N/A"){
    
this.basic "Element:" SPC this.data[1NL 
               
"Cast Time:" this.data[2] - 0.05 SPC "Cooldown:" this.data[3];
  }
  else{
    
this.basic "Element:" SPC this.data[1NL 
               
"Cast Time:" this.data[2] - 0.05 SPC "Cooldown:" this.data[3NL 
               
"Magic:"this.data[4SPC "Mana:" this.data[5];
  }
  
this.description this.data[6];
  
  
MyGUI_SkillGUI_MultiLine1.text this.sname NL this.basic NL this.description;
}

function 
onUpdateList(){
  
//MyGUI_SkillGUI_MultiLine1.text = this.sname NL this.basic NL this.description;
}

function 
MyGUI_SkillGUI_TextList1_Scroll.onSelect(){
  
player.chat params;

In addition I might as well double check before I end up messing something up:
Once this is working, would I use findweapon("weapon name").destroy(); on the clientside to delete weapons from the player? Just afraid of the weapon being deleted from the npcserver like it did last time. I called this.destroy() in a weapon script before to delete it from the player. Just want to make sure that it doesn't behave unexpectedly.
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #2  
Old 06-25-2011, 07:55 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
why not remove it serverside with removeweapon()
Reply With Quote
  #3  
Old 06-25-2011, 08:11 PM
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
destroy() will only delete the weapon NPC when used on the serverside. As stated, though, you should use removeWeapon() to remove a weapon (duh) from the player.
Reply With Quote
  #4  
Old 06-25-2011, 08:15 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Alright. I wasn't aware of removeWeapon();

what about my hasweapon problem though? Any ideas?
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #5  
Old 06-25-2011, 08:22 PM
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
You could use a custom function for it:
PHP Code:
function hasWeapon(wName) {
  for (
temp.wplayer.weapons)
    if (
w.name == wName)
      return 
true;

  return 
false;

It'd probably be better to do the checks on the serverside though.
Reply With Quote
  #6  
Old 06-25-2011, 08:22 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
Yeah hasweapon definitely seems to be depreciated now both with and without "player.", I think you have to use:

PHP Code:
if(player.findweapon("name") != NULL){} 
With the "player." removed when Clientside.
Reply With Quote
  #7  
Old 06-25-2011, 08:48 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Hm. I went with mike's suggestion for now. It seems more secure and this is one of the few weapons that checks to see if a player has a weapon. It appears to be working at the moment. Thanks for the help!
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #8  
Old 06-25-2011, 08:50 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
to clarify what Crow and Thor means; hasWeapon is GS1 and does not exist in GS2.

however, you shouldn't have to loop thought the player's weapons to find if you have a weapon or not. findWeapon() should do the trick.

findWeapon(str weaponname) - returns str (object?)
if you have the weapon, or 0 if you don't have it.
with this, you could make a hasWeapon(weap) function by checking if findWeapon() is equal to 0, if that is so, return false, if not, return true. this works on both client and serverside.

e; no pre-scripted for you , should be simple enuf with my "description"
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you

Last edited by Deas_Voice; 06-25-2011 at 08:51 PM.. Reason: linebreaks
Reply With Quote
  #9  
Old 06-25-2011, 08:52 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Quote:
Originally Posted by Deas_Voice View Post
to clarify what Crow and Thor means; hasWeapon is GS1 and does not exist in GS2.

however, you shouldn't have to loop thought the player's weapons to find if you have a weapon or not. findWeapon() should do the trick.

findWeapon(str weaponname) - returns str (object?)
if you have the weapon, or 0 if you don't have it.
with this, you could make a hasWeapon(weap) function by checking if findWeapon() is equal to 0, if that is so, return false, if not, return true. this works on both client and serverside.

e; no pre-scripted for you , should be simple enuf with my "description"
Ah, I'll have to remember that! Also I had no idea that the function was completely absent in GS2. I'm thinking /scripthelp hasweapon should be updated to at least tell the user that it's not functional online.
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #10  
Old 06-25-2011, 08:54 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by Jiroxys7 View Post
Ah, I'll have to remember that! Also I had no idea that the function was completely absent in GS2. I'm thinking /scripthelp hasweapon should be updated to at least tell the user that it's not functional online.
Quote:
Originally Posted by /scripthelp hasweapon
No matching script function found!
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #11  
Old 06-25-2011, 08:54 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
There's also:

temp.hasWeapon = findweapon("weapon") in player.weapons;
__________________
Quote:
Reply With Quote
  #12  
Old 06-25-2011, 08:59 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Quote:
Originally Posted by Deas_Voice View Post
/scripthelp hasweapon

not

/scripthelp hasWeapon

(caps difference)
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #13  
Old 06-25-2011, 09:01 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by Jiroxys7 View Post
/scripthelp hasweapon
No matching script function found!
Quote:
Originally Posted by Jiroxys7 View Post
/scripthelp hasWeapon
No matching script function found!


...what?
there's no case sensitivity on scripthelp btw.
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #14  
Old 06-25-2011, 09:05 PM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Quote:
Originally Posted by Deas_Voice View Post
No matching script function found!

No matching script function found!


...what?
there's no case sensitivity on scripthelp btw.
Wow, you're right. That is ultra weird. I could've sworn the lowercase one brought up something like:
Script help for 'hasweapon':
hasweapon(str) - returns object
TServerPlayer hasweapon(str) - returns object
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #15  
Old 06-25-2011, 09:06 PM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
hasweapon was removed

findweapon("weapon") returns boolean (true / false)
__________________
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:45 PM.


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