Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   hasweapon() not working correctly? (https://forums.graalonline.com/forums/showthread.php?t=134263660)

Jiroxys7 06-25-2011 07:50 PM

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.

Cubical 06-25-2011 07:55 PM

why not remove it serverside with removeweapon()

Crow 06-25-2011 08:11 PM

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.

Jiroxys7 06-25-2011 08:15 PM

Alright. I wasn't aware of removeWeapon();

what about my hasweapon problem though? Any ideas?

Crow 06-25-2011 08:22 PM

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.

ffcmike 06-25-2011 08:22 PM

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.

Jiroxys7 06-25-2011 08:48 PM

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!

Deas_Voice 06-25-2011 08:50 PM

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"

Jiroxys7 06-25-2011 08:52 PM

Quote:

Originally Posted by Deas_Voice (Post 1656166)
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.

Deas_Voice 06-25-2011 08:54 PM

Quote:

Originally Posted by Jiroxys7 (Post 1656167)
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!

:confused:

fowlplay4 06-25-2011 08:54 PM

There's also:

temp.hasWeapon = findweapon("weapon") in player.weapons;

Jiroxys7 06-25-2011 08:59 PM

Quote:

Originally Posted by Deas_Voice (Post 1656168)
:confused:

/scripthelp hasweapon

not

/scripthelp hasWeapon

(caps difference)

Deas_Voice 06-25-2011 09:01 PM

Quote:

Originally Posted by Jiroxys7 (Post 1656170)
/scripthelp hasweapon

No matching script function found!
Quote:

Originally Posted by Jiroxys7 (Post 1656170)
/scripthelp hasWeapon

No matching script function found!


...what?
there's no case sensitivity on scripthelp btw.

Jiroxys7 06-25-2011 09:05 PM

Quote:

Originally Posted by Deas_Voice (Post 1656171)
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

xAndrewx 06-25-2011 09:06 PM

hasweapon was removed

findweapon("weapon") returns boolean (true / false)


All times are GMT +2. The time now is 02:14 PM.

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