Raised This Month: $ Target: $400
 0% 

Giving weapons from a "list"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Floody
Member
Join Date: Jan 2012
Old 03-19-2014 , 19:33   Giving weapons from a "list"
Reply With Quote #1

Hey
what's wrong with this code? I want to give a player a random weapon. I tried this, didn't work. Anyone has an idea why?

PHP Code:
    new String:weaponArray[] =
    {
        
"weapon_glock",
        
"weapon_usp",
        
"weapon_mac10",
        
"weapon_deagle",
        
"weapon_p228"
    
};
    new 
randomNum GetRandomInt(15);
    
GivePlayerItem(clientweaponArray[randomNum]); 
Thanks in advance!

Last edited by Floody; 03-19-2014 at 19:34.
Floody is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 03-19-2014 , 20:41   Re: Giving weapons from a "list"
Reply With Quote #2

Well, I would start with having a 2 dimensions array. I'm surprised your code compile. A string is already an array. Having many array you have an array of arrays --> [][].

i.e.

Code:
new const String:weaponNames[35][ 16 ] = 
{ 
	"none",			"p228",			"glock",		"scout",
	"hegrenade",	"xm1014",		"c4",			"mac10",
	"aug",			"smokegrenade",	"elite",		"fiveseven",
	"ump45",		"sg550",		"galil",		"famas",
	"usp",			"awp",			"mp5navy",		"m249",
	"m3",			"m4a1",			"tmp",			"g3sg1",
	"flashbang", 	"deagle",		"sg552",		"ak47",
	"knife",		"p90",			"shield",		"vest",
	"vesthelm",		"nvgs",			"defuser"
};
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work

Last edited by RedSword; 03-24-2014 at 19:26. Reason: woops missing ","
RedSword is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 03-20-2014 , 20:06   Re: Giving weapons from a "list"
Reply With Quote #3

And the index of array starts at 0, so you should do
PHP Code:
new randomNum GetRandomInt(04); 
instead of
PHP Code:
new randomNum GetRandomInt(15); 
KissLick is offline
Root_
Veteran Member
Join Date: Jan 2012
Location: ryssland
Old 03-24-2014 , 08:50   Re: Giving weapons from a "list"
Reply With Quote #4

Let the array size to be defined by compiler, so
Code:
new const String:weaponNames[][] = {     "none",         "p228",         "glock",        "scout",     "hegrenade",    "xm1014",       "c4",           "mac10",     "aug",          "smokegrenade"  "elite",        "fiveseven",     "ump45",        "sg550",        "galil",        "famas",     "usp",          "awp",          "mp5navy",      "m249",     "m3",           "m4a1",         "tmp",          "g3sg1",     "flashbang",    "deagle",       "sg552",        "ak47",     "knife",        "p90",          "shield",       "vest",     "vesthelm",     "nvgs",         "defuser" };
To give random weapon from a list, you can use GetRandomInt(0, sizeof(weaponNames)-1);
__________________


dodsplugins.com - Plugins and Resources for Day of Defeat
http://twitch.tv/zadroot
Root_ is offline
Reply



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 -4. The time now is 07:45.


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