Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 


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 01:49 PM.


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