This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Choosing a random player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 04-15-2024 , 17:12   Re: Choosing a random player
Reply With Quote #1

Quote:
Originally Posted by tedaimlocks View Post
Can someone help with the code below?I dont know how to get a random player and give them the stuff

Spoiler
Code:
public ChooseHero() {     // Choose a random player every round and give them the stuff under         new players[32], num; get_players(players, num, "a")         new id = players[random(num)]         set_user_armor(id, get_user_armor(id) + 150)     set_user_health(id, get_user_health(id) + 150)         give_item(id, "weapon_hegrenade")     give_item(id, "weapon_flashbang")         new szName[32]; get_user_name(id, szName, charsmax(szName))         ColorChat(0, GREEN, "^x01[^x04SPK ZM^x01]^x04 %s ^x03was chosen to be the ^x04Hero ^x03of the round! They have got ^x04+150HP+150AP+MULTIJUMPS", szName) }
__________________
mlibre is offline
tedaimlocks
Senior Member
Join Date: Jan 2024
Old 04-16-2024 , 02:34   Re: Choosing a random player
Reply With Quote #2

Quote:
Originally Posted by mlibre View Post
Code:
public ChooseHero() {     // Choose a random player every round and give them the stuff under         new players[32], num; get_players(players, num, "a")         new id = players[random(num)]         set_user_armor(id, get_user_armor(id) + 150)     set_user_health(id, get_user_health(id) + 150)         give_item(id, "weapon_hegrenade")     give_item(id, "weapon_flashbang")         new szName[32]; get_user_name(id, szName, charsmax(szName))         ColorChat(0, GREEN, "^x01[^x04SPK ZM^x01]^x04 %s ^x03was chosen to be the ^x04Hero ^x03of the round! They have got ^x04+150HP+150AP+MULTIJUMPS", szName) }
It gives errors if no player is connected ( i think )

run time error 4 : index out of bounds

Last edited by tedaimlocks; 04-16-2024 at 03:42.
tedaimlocks is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 04-16-2024 , 08:17   Re: Choosing a random player
Reply With Quote #3

Quote:
Originally Posted by WATCH_D0GS UNITED View Post
Based on what its said, it doesn't matter:
----------------------------------

native random(max);

Description

Returns a random number between 0 and a specified upper bound.

----------------------------------
so if there are 3 players, let's say, you can throw a larger random number like 4 you mean

Quote:
Originally Posted by tedaimlocks View Post
...run time error 4 : index out of bounds
test

Code:
public ChooseHero() {     // Choose a random player every round and give them the stuff under         new players[32], num; get_players(players, num, "a")         if( !num )     {         return     }         //... }
__________________

Last edited by mlibre; 04-16-2024 at 08:24.
mlibre 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 04:54.


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