AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Random options...... (https://forums.alliedmods.net/showthread.php?t=25723)

organizedKaoS 03-19-2006 07:29

Random options......
 
How can I, for example, assign a different starting weapon on round change? Last round, started with ak47, then next round plugin chooses at random from within itself a new primary weapon to give. So on next round, player gets auto shotgun instead. And so on for entire map. Anybody know how to do this? Thanks

[ --<-@ ] Black Rose 03-19-2006 08:53

sumthin' like this?
Code:
#include <amxmodx> #include <fun> #define PLUGIN "" #define VERSION "1.0" #define AUTHOR "[ --<-@ ]" #define MAX_WEAPONS 25 new g_szWeaps[MAX_WEAPONS][] = {     "ak47", "aug",     "awp", "deagle",     "elite", "famas",     "fiveseven", "g3sg1",     "galil", "glock18",     "m249", "m3",     "m4a1", "mac10",     "mp5navy", "p228",     "p90", "scout",     "sg550", "sg552",     "tmp", "ump45",     "usp", "xm1014",     "shield" } public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_event("ResetHud", "func", "be") } public func(id) {     new j = random_num( 0, MAX_WEAPONS - 1 )     for( new i = 0; i < MAX_WEAPONS; i++ ) {         if ( i == j ) {             new weap[25]             format(weap , 24 , "weapon_%s" , g_szWeaps[i])             give_item(id , weap)             ammo_up(id)             client_print( id, print_chat, "[WPN] Gave : %s", g_szWeaps[i] )         }     } } public ammo_up(id) {     give_item(id, "item_thighpack")     give_item(id, "weapon_hegrenade")     give_item(id, "weapon_flashbang")     give_item(id, "weapon_flashbang")     give_item(id, "item_assaultsuit")     give_item(id, "weapon_smokegrenade")     for ( new i = 0 ; i < 20 ; i++ ) {         give_item(id, "ammo_9mm")         give_item(id, "ammo_50ae")         give_item(id, "ammo_57mm" )         give_item(id, "ammo_357sig")         give_item(id, "ammo_762nato")         give_item(id, "ammo_556nato" )         give_item(id, "ammo_buckshot" )         give_item(id, "ammo_338magnum" )         give_item(id, "ammo_556natobox" )         give_item(id, "ammo_45acp")     } }

VEN 03-19-2006 12:48

ResetHUD usually is a player spawn but not round change.

Quote:

Originally Posted by amxx wiki
Precompute what can be precomputed

Better put to the global array exact weapon names.
Then your func would be:
Code:
public func(id) {             new i = random(MAX_WEAPONS)             give_item(id , g_szWeaps[i])             ammo_up(id)             client_print( id, print_chat, "[WPN] Gave : %s", g_szWeaps[i][7] ) }

organizedKaoS 03-19-2006 13:56

Quote:

Originally Posted by VEN
ResetHUD usually is a player spawn but not round change.

Quote:

Originally Posted by amxx wiki
Precompute what can be precomputed

Better put to the global array exact weapon names.
Then your func would be:
Code:
public func(id) {             new i = random(MAX_WEAPONS)             give_item(id , g_szWeaps[i])             ammo_up(id)             client_print( id, print_chat, "[WPN] Gave : %s", g_szWeaps[i][7] ) }

So if I define the weapon names in the plugin and use this set, on every round change, a random weapon will be given? Ill try this while I wait for a response. Thanks peeps :lol:

wouter 03-19-2006 14:00

Quote:

Originally Posted by [ --<-@
Black Rose]
Code:
#include #define MAX_WEAPONS 25 new g_szWeaps[MAX_WEAPONS][]

why dont you do
Code:
new g_szWeaps[25][]

organizedKaoS 03-19-2006 18:52

IDK

Brad 03-19-2006 21:02

A good reason to use a define instead of the number itself is to maintain code readibility. That's a good programming practice.

organizedKaoS 03-19-2006 21:52

Quote:

Originally Posted by VEN
Better put to the global array exact weapon names.
Then your func would be:
Code:
public func(id) {             new i = random(MAX_WEAPONS)             give_item(id , g_szWeaps[i])             ammo_up(id)             client_print( id, print_chat, "[WPN] Gave : %s", g_szWeaps[i][7] ) }

That didnt seem to work for me...but this
Code:
public func(id) {     new j = random_num( 0, MAX_WEAPONS - 1 )     for( new i = 0; i < MAX_WEAPONS; i++ ) {         if ( i == j ) {             new weap[25]             format(weap , 24 , "weapon_%s" , g_szWeaps[i])             give_item(id , weap)             ammo_up(id)             client_print( id, print_chat, "[WPN] Gave : %s", g_szWeaps[i] )         }
did and yeah :lol: .....Thanks everyone who helped in here :lol: :lol: :lol:

Xanimos 03-19-2006 22:06

Quote:

Originally Posted by organizedKaoS
Quote:

Originally Posted by VEN
Better put to the global array exact weapon names.
Then your func would be:
Code:
public func(id) {             new i = random(MAX_WEAPONS)             give_item(id , g_szWeaps[i])             ammo_up(id)             client_print( id, print_chat, "[WPN] Gave : %s", g_szWeaps[i][7] ) }

That didnt seem to work for me...but this
Code:
public func(id) {     new j = random_num( 0, MAX_WEAPONS - 1 )     for( new i = 0; i < MAX_WEAPONS; i++ ) {                     if ( i == j ) {             new weap[25]             format(weap , 24 , "weapon_%s" , g_szWeaps[i])             give_item(id , weap)             ammo_up(id)             client_print( id, print_chat, "[WPN] Gave : %s", g_szWeaps[i] )         }
did and yeah :lol: .....Thanks everyone who helped in here :lol: :lol: :lol:

Just use VEN's but change it to

Code:
public func(id) {             new i = random(MAX_WEAPONS)             new weap[25]             format(weap , 24 , "weapon_%s" , g_szWeaps[i])             give_item(id , g_szWeaps[i])             ammo_up(id)             client_print( id, print_chat, "[WPN] Gave : %s", g_szWeaps[i]) }

VEN 03-20-2006 03:55

Code:
public func(id) {     new i = random(MAX_WEAPONS)     give_item(id , g_szWeaps[i])     ammo_up(id)     client_print( id, print_chat, "[WPN] Gave : %s", g_szWeaps[i][7] ) }
I tesed that function, it's fine.
Quote:

Better put to the global array exact weapon names.
It didn't work for you because you probably didn't specified full weapon names:
Code:
new g_szWeaps[MAX_WEAPONS][] = {     "weapon_ak47", "weapon_aug",     "weapon_awp", "weapon_deagle",     "weapon_elite", "weapon_famas",     "weapon_fiveseven", "weapon_g3sg1",     "weapon_galil", "weapon_glock18",     "weapon_m249", "weapon_m3",     "weapon_m4a1", "weapon_mac10",     "weapon_mp5navy", "weapon_p228",     "weapon_p90", "weapon_scout",     "weapon_sg550", "weapon_sg552",     "weapon_tmp", "weapon_ump45",     "weapon_usp", "weapon_xm1014",     "weapon_shield" }
Also if you still use ResetHUD, delay should be used:
Code:
public func(id) {     set_task(0.1, "func2", id) } public func2(id) {     new i = random(MAX_WEAPONS)     give_item(id , g_szWeaps[i])     ammo_up(id)     client_print( id, print_chat, "[WPN] Gave : %s", g_szWeaps[i][7] ) }

You do not have to use format method, it only seems as efficient but in fact that's not so.


All times are GMT -4. The time now is 16:36.

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