AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   help with arrays and vars (https://forums.alliedmods.net/showthread.php?t=51070)

mexykanu 02-10-2007 16:24

help with arrays and vars
 
i'm trying to make something to give people weapons.

i've given at the begining of the plugin the var new g_weapon_name[20]
now in the "main" public i'm trying to look in g_weapon_name, as folows:

Code:

if(g_weapon_name=="m4a1") {
        give_item(id,CSW_M4A1)
}
else {
if

etc etc etc

but it won't work... it gives me this message: "Array must be indexed (variable g_weapon_name)"

[ --<-@ ] Black Rose 02-10-2007 16:30

Re: help with arrays and vars
 
give_item(id, "weapon_m4a1")

This is how you compare a string.
Code:
if ( equali(g_weapon_name, "m4a1") )

or
Code:
if ( g_weapon_name[0] == 'm' && g_weapon_name[1] == '4' && g_weapon_name[2] == 'a' && g_weapon_name[3] == '1' ) //

but if you wanna give a user by a cmd and is reading the weapon from an argument:
Code:
new arg[32], give_weapon[64] read_argv(1, arg, 31) formatex(give_weapon, 63, "weapon_%s", arg) give_item(id, give_weapon)

mexykanu 02-10-2007 16:49

Re: help with arrays and vars
 
now.. the strangest thing is... i tried this before

Code:

if ( equali(g_weapon_name, "m4a1") )
and now it worked :|

the second strange thing is that
Code:

give_item(id, "weapon_m4a1")
this wouldn't work before.


thanks a lot. i hope it will get approved :D

mexykanu 02-11-2007 04:56

Re: help with arrays and vars
 
i've got another question.. it's related with this plugin so it's no use to make another topic

the script is supposed to do this: (amx_giveweapon name m4a1)
-give weapon
-give ammo X times ( X clips )

the script works, but like this: ( same command )
-give weapon
-nothing

if you run it again, it gives you the ammo for that weapon , but just one clip at a time (same command )

this is the script
Code:

}else if(equali(g_weapon_name, "m4a1" )) {
  give_item(id, "weapon_m4a1")
  give_item(id, "ammo_556nato")
  give_item(id, "ammo_556nato")
  give_item(id, "ammo_556nato")
  }else

i don't know how to "pause" between actions, do you know what i can do ?

[ --<-@ ] Black Rose 02-11-2007 05:59

Re: help with arrays and vars
 
Code:
#include <amxmodx> #include <amxmisc> #include <fun> #include <cstrike> new const g_Weapons[33][] = {     "", "p228", "shield", "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", "kevlar", "assault" } new g_MaxBPAmmo[33] = {0,52,0,90,0,32,0,100,90,0,120,100,100,90,90,90,100,120,30,120,200,21,90,120,90,0,35,90,90,0,100,0,0} public plugin_init() {     register_plugin("", "", "")     register_concmd("amx_giveweapon", "cmd_giveweapon") } public cmd_giveweapon(id) {     if ( ! ( get_user_flags(id) & ADMIN_KICK ) )         return PLUGIN_CONTINUE         new arg1[32], arg2[32]         read_argv(1, arg1, 31)     read_argv(2, arg2, 31)          new target = cmd_target(id, arg1, 0)         if ( ! target )         return PLUGIN_CONTINUE         new weap[40] = "weapon_"         for ( new i = 1; i < 33; i++ ) {                 if( equali(arg2, g_Weapons[i]) ) {                         copy(weap[7], 32, g_Weapons[i])                         give_item(target , weap)                         if ( i != 2 && i != 4 && i != 6 && i != 9 && i != 25 && i != 29 && i != 31 && i != 32 )                 cs_set_user_bpammo(id, i, g_MaxBPAmmo[i])                         return PLUGIN_CONTINUE         }     }         client_print(id, print_console, "Weapon ^"%s^" was not found", arg2)         return PLUGIN_CONTINUE }

mexykanu 02-11-2007 06:13

Re: help with arrays and vars
 
i'll use this:
Code:

cs_set_user_bpammo ( id, i, g_MaxBPAmmo[i]) )
thanks

edit: still not giving ammo... ( i also tried your script )

[ --<-@ ] Black Rose 02-11-2007 06:42

Re: help with arrays and vars
 
show me how you used it in your script.

mexykanu 02-11-2007 06:43

Re: help with arrays and vars
 
Code:

}else if(equali(g_weapon_name, "m4a1" )) {
  cs_set_user_bpammo ( id, CSW_M4A1, 90)

etc

i think i'll make another public, to give ammo to all weapons. it will be called when the "main" public is finished.


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

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