AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   question with get_user_weapons (https://forums.alliedmods.net/showthread.php?t=51212)

mexykanu 02-13-2007 15:49

question with get_user_weapons
 
how can i look at what weapons a user has ?

will this work ??

Code:

new weapons[32]
new num
get_user_weapons(id, weapons, num)
 

if (containi(Weapons,"CSW_M4A1") ) { ACTIONS


teame06 02-13-2007 16:05

Re: question with get_user_weapons
 
Code:
    new weapons[32]     new num, weapid     get_user_weapons(id, weapons, num)     for(new i = 0; i < num; i++)     {         weapid = weapons[i];         if(weapid == CSW_M4A1)         {             // Do stuff         }       }

mexykanu 02-14-2007 05:49

Re: question with get_user_weapons
 
oh so that's what i was doing wrong:

Code:

  new weapons[32]
  new num, weapid
  get_user_weapons(id, weapons, num)
 
  for(new i = 0; i < num; i++)
  {
      weapid = weapons[i];
  }
 
if(weapid == CSW_M4A1)
      {
          // Do stuff
      }

thanks

another question:
Code:

if(weapid == CSW_M4A1)
are you sure this will look and see if in the weapons there is a m4a1 ? because it looks like it will work only if weapid has ONLY "CSW_M4A1"

[ --<-@ ] Black Rose 02-14-2007 07:10

Re: question with get_user_weapons
 
the 'if' part is suppose to be inside the loop as teame06 posted.

mexykanu 02-14-2007 07:36

Re: question with get_user_weapons
 
ok i got that, but if i use only if , will it look in weapid only for CSW_M4A1 ? i mean.. it will not work if i have 100 weapons, it only looks for that field.

[ --<-@ ] Black Rose 02-14-2007 09:56

Re: question with get_user_weapons
 
weapid is different in every loop.
Code:
new weapons[32], num get_user_weapons(id, weapons, num)
now the user had 3 weapons; knife, usp and m4a1.
you check the loop if user has m4a1.
Code:
for(new i = 0; i < num; i++) {     if ( weapons[i] == CSW_M4A1 ) {         // This is called when user has m4a1        }    }
That will check first weapons[0] then weapons[1] then weapons[2]. If any of the wepons[x] is CSW_M4A1 the code will be called.

lets say array would be
Code:
weapons[0] = CSW_KNIFE weapons[1] = CSW_USP weapons[2] = CSW_M4A1
Then the loop would first check weapons[0] if that is CSW_M4A1. But that if statement would return false so the code will continue, when it finds CSW_M4A1 the if statement will return true and code would be called.
Then it would still continue untill the end if you don't stop it urself.

Code:
new weapons[32], num get_user_weapons(id, weapons, num) for(new i = 0; i < num; i++) {     weapid = weapons[i]; // This is only necessary if you use this value more than once.     if ( weapid == CSW_M4A1 ) {         // This is called when user has a m4a1     }     else if ( weapid == CSW_AK47 ) {         // This is called when user has an ak47     } }

Alka 02-14-2007 10:22

Re: question with get_user_weapons
 
hi. black rose :P how can i make a HUD msg to show the "curent weapon" in hand? Thanks ;)

Ex: Weapon: Ak47
Weapon: AWP
Weapon glock18

Ps: I try with this above functions!but give me an error! :|

mexykanu 02-14-2007 12:06

Re: question with get_user_weapons
 
black rose, i don't know if it matters for you, but you'll always recieve +karma from me. thanks, i understand now

[ --<-@ ] Black Rose 02-14-2007 17:33

Re: question with get_user_weapons
 
Quote:

Originally Posted by Alka (Post 440119)
hi. black rose :P how can i make a HUD msg to show the "curent weapon" in hand? Thanks ;)

Ex: Weapon: Ak47
Weapon: AWP
Weapon glock18

Ps: I try with this above functions!but give me an error! :|

Code:
#include <amxmodx> new const g_Weapons[][] = {     "", "p228", "", "scout", "hegrenade",     "xm1014", "c4", "mac10", "aug", "smokegrenade",     "elite", "fiveseven", "ump45", "sg550", "galil",     "famas", "usp", "glock18", "awp", "mp5",     "m249", "m3", "m4a1", "tmp", "g3sg1",     "flashbang", "deagle", "sg552", "ak47", "knife",     "p90" }; new g_HUD[64] = "Weapon: %s"; public plugin_init() {     register_event("CurWeapon", "event_CurWeapon", "b") } public event_CurWeapon(id) {     new temp = get_user_weapon(id, temp, temp)     set_hudmessage(255, 0, 255, -1.0, 0.35, 0, 6.0, 12.0, 0.1, 0.1, 3)     show_hudmessage(id, g_HUD, g_Weapons[temp])     // g_Weapons[read_data(2)], Not a good way. Switch from knife to another weapons still returns knife. }

Alka 02-14-2007 18:28

Re: question with get_user_weapons
 
Oouuu thanks again man...It's worknig Perfect! :D


All times are GMT -4. The time now is 00:41.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.