Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Weapon Names Problem (https://forums.graalonline.com/forums/showthread.php?t=134262630)

PhilSmith 03-31-2011 06:06 PM

Weapon Names Problem
 
I've been trying to make a custom inventory and while doing so I have come across a slight problem. I want to make the inventory hide the typical "-" and "*" weapons, however my check is not working. It seems as though the weapons that are named with these starting characters, are actually not (in the mind of my script).

PHP Code:

for(i=0;i<player.weapon.size();i++){
    if(!
player.weapon[i].name.starts("-")){
      new 
GuiBitmapButtonCtrl("PhilSmith_Weapon_"@i){
        
profile=PhilSmith_HUDButtons;
        
PhilSmith_Inventory.x+(i*40);
        
PhilSmith_Inventory.y+15;
        
normalbitmap temp.imgs[i];
        
mouseoverbitmap temp.imgs[i];
        
pressedbitmap temp.imgs[i];
        
width 32;
        
height=32;
        
text=player.weapon[i].name;
      }
    }
  } 

Thanks for taking the time to look this over to help me. :D

xAndrewx 03-31-2011 06:25 PM

PHP Code:

for(i=0;i<player.weapons.size();i++){
    if(
player.weapons[i].name.starts("-")) continue;
    if(
player.weapons[i].name.pos("/")) continue;
    new 
GuiBitmapButtonCtrl("PhilSmith_Weapon_"@i){
      
profile=PhilSmith_HUDButtons;
      
PhilSmith_Inventory.x+(i*40);
      
PhilSmith_Inventory.y+15;
      
normalbitmap temp.imgs[i];
      
mouseoverbitmap temp.imgs[i];
      
pressedbitmap temp.imgs[i];
      
width 32;
      
height=32;
      
text=player.weapons[i].name;
    }
  } 

Use player.weapon[S] not player.weapon :)

gj on coding though ^^

fowlplay4 03-31-2011 08:16 PM

Well let's throw some more detail your way...

player.weapons - holds a list of weapon objects that you currently have:

PHP Code:

for (temp.weaponplayer.weapons) {
  echo(
temp.weapon.name);


You can check if a player has a certain weapon like this:

PHP Code:

// Setup: Weapon name to check for
temp.weaponname "-System";

// Method using findweapon
temp.weapon findweapon(temp.weaponname);
if (
temp.weapon in player.weapons) {
  echo(
"Player has " temp.weaponname);
}

// Directly referring to the weapon object
if ((@temp.weaponnamein player.weapons) {
  echo(
"Player has " temp.weaponname);


You can even access functions and variables in other weapons:

PHP Code:

findweapon("-System").someAwesomeFunction();
echo((@
"-System").answer)); // echos "3" 

Weapon: -System

PHP Code:

public function someAwesomeFunction() {
  echo(
"awesomeness detected.");
}

this.answer "3"

The methods are basically the same, except the findweapon way is little more clear (imo) to other people reading the script.

PhilSmith 04-01-2011 02:02 AM

Thanks guys. Snk your always a big help :). Thanks fowlplay for going out of your way to teach :) Especially teaching more than I asked for. It gives me more knowledge, and more possible way to do something like this :D


All times are GMT +2. The time now is 09:46 AM.

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