Raised This Month: $ Target: $400
 0% 

Give gun randomly


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zerbbi
Junior Member
Join Date: Aug 2009
Old 02-13-2012 , 09:54   Give gun randomly
Reply With Quote #1

Hello, i need help. I want to make plugin to give flashbang randomly to only one player with ADMIN_LEVEL_H flag every round. Now, i have this condition:
if random(3) = 1 then give(flashbang)
but it is unfair, sometimes every VIP have flash, sometimes nobody have flash. Can you help? Thanks
zerbbi is offline
anakin_cstrike
Veteran Member
Join Date: Nov 2007
Location: Romania
Old 02-13-2012 , 10:32   Re: Give gun randomly
Reply With Quote #2

sometimes = random, you never know. If you want to make sure he gets a weapon then it wouldn't be random, right?
__________________

anakin_cstrike is offline
Devil259
Veteran Member
Join Date: Dec 2009
Location: France (59)
Old 02-13-2012 , 10:43   Re: Give gun randomly
Reply With Quote #3

You can do something like that :

Code:
new iRandom = random_num( 1 , 3 ) switch( iRandom ) {     case 1:give_item( id , "weapon_flashbang" );     case 2://...     case 3://... }
__________________
You can do anything you set your mind to, man.

Devil259 is offline
RoaR
Member
Join Date: Dec 2011
Old 02-13-2012 , 10:57   Re: Give gun randomly
Reply With Quote #4

PHP Code:
#include <amxmodx>
#include <fun>


new iRandom random_num(1,3);

if(
get_user_flags(id) && ADMIN_LEVEL_H) {
    switch (
iRandom): {
        case 
1: { give_item(id,"weapon_flashbang") }
        case 
2: { // smth here 
        
}
            case 
3: { // smth here 
            
}
        }
    }

I may declared more } then i should.

This uses fun and amxmodx module.

Last edited by RoaR; 02-13-2012 at 11:00.
RoaR is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-13-2012 , 10:58   Re: Give gun randomly
Reply With Quote #5

Would be better to do this:

Code:
#include <amxmodx> #include <fun> #include <hamsandwich> new gPlayerToGetFlashBang; public plugin_init() {     register_event("HLTV", "EventNewRound", "a", "1=0", "2=0");         RegisterHam(Ham_Spawn, "player", "FwdPlayerSpawnPost", 1); } public client_disconnect(id) {     if(id == gPlayerToGetFlashBang) {         gPlayerToGetFlashBang = 0;     } } public EventNewRound() {     new players[32], pnum;     get_players(players, pnum, "a");         for(new i = 0; i < pnum; i++) {         if(~get_user_flags(players[i]) & ADMIN_LEVEL_H) {             players[i--] = players[--pnum];         }     }         gPlayerToGetFlashBang = pnum ? players[(pnum > 1) ? random(pnum) : 0] : 0; } public FwdPlayerSpawnPost(id) {     if(id == gPlayerToGetFlashBang && is_user_alive(id)) {         give_item(id, "weapon_flashbang");     } }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
zerbbi
Junior Member
Join Date: Aug 2009
Old 02-15-2012 , 03:08   Re: Give gun randomly
Reply With Quote #6

Thank you very much, i'll try.
zerbbi is offline
zerbbi
Junior Member
Join Date: Aug 2009
Old 02-15-2012 , 08:14   Re: Give gun randomly
Reply With Quote #7

Thank you very much exolent! It's woking pefectly and giving flash is fair. Thanks again
zerbbi is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 02-15-2012 , 08:33   Re: Give gun randomly
Reply With Quote #8

Exolent sorry ,but you can explain please why you use ~ in the if statement ?
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
Devil259
Veteran Member
Join Date: Dec 2009
Location: France (59)
Old 02-15-2012 , 08:52   Re: Give gun randomly
Reply With Quote #9

if(~get_user_flags(players[i]) & ADMIN_LEVEL_H)

is the same as

if(!(get_user_flags(players[i]) & ADMIN_LEVEL_H))
__________________
You can do anything you set your mind to, man.

Devil259 is offline
RoaR
Member
Join Date: Dec 2011
Old 02-15-2012 , 09:11   Re: Give gun randomly
Reply With Quote #10

Quote:
Originally Posted by Devil259 View Post
if(~get_user_flags(players[i]) & ADMIN_LEVEL_H)

is the same as

if(!(get_user_flags(players[i]) & ADMIN_LEVEL_H))

Thanks.
RoaR 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 23:41.


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