Raised This Month: $ Target: $400
 0% 

[Help] Weapon Chance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tepAse
Junior Member
Join Date: Jun 2009
Old 07-25-2009 , 14:17   [Help] Weapon Chance
Reply With Quote #1

I've tried to make an Weapon Chance plugin, i get no error's but it doesnt give out items ingame.. Srry bad english.

[EDIT] It works with if you play without freezetime

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

#define PLUGIN    "Weapon Chance"
#define AUTHOR    "FaktuM"
#define VERSION    "1.0"

new gMaxPlayers;
new 
szName[32];

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
register_event("HLTV""eventRoundStart""a""1=0""2=0");
    
    
gMaxPlayers get_maxplayers();
}

public 
eventRoundStart()
{
    
set_task(5.0"WeaponChance");
}

public 
WeaponChance()
{
    for(new 
id 1id <= gMaxPlayersid++)
    {
        if(
is_user_connected(id) && is_user_alive(id))
        {
            switch(
get_user_team(id))
            {
                case 
1:
                {
                    if(
random_num(0100) <= 20)
                    {
                        
give_item(id"weapon_hegrenade");
                        
client_print(idprint_chat"You got a HE! (20%% chance)");
                    }
                }
                case 
2:
                {
                    if(
random_num(0100) <= 30)
                    {
                        
give_item(id"weapon_flashbang");
                        
client_print(idprint_chat"You got a flashbang! (30%% chance)");
                    }
                }
                case 
3:
                {
                    if(
random_num(0100) <= 1)
                    {
                        
give_item(id"weapon_awp");
                        
cs_set_weapon_ammo(find_ent_by_owner(2"weapon_awp"id), 1);
                        
client_print(idprint_chat"You got an awp with 2 bullets! (1%% chance)");
                        
                        
get_user_name(idszName31);
                        
client_print(0print_chat"[Weapon Chance] %s has recived an awp with two bullets, aware!"szName);
                    }
                }
                case 
4:
                {
                    if(
random_num(0100) <= 5)
                    {
                        
set_user_health(id150);
                        
client_print(idprint_chat"You recived 150 health! (5%% chance)");
                    }
                }
                case 
5:
                {
                    if(
random_num(0100) <= 10)
                    {
                        
give_item(id"weapon_fiveseven");
                        
cs_set_weapon_ammo(find_ent_by_owner(1"weapon_fiveseven"id), 1);
                        
client_print(idprint_chat"You recived an Fiveseven with 1 bullet! (10%% chance)");
                    }
                }
                case 
6:
                {
                    if(
random_num(0100) <= 5)
                    {
                        
give_item(id"weapon_deagle");
                        
cs_set_weapon_ammo(find_ent_by_owner(1"weapon_deagle"id), 1);
                        
client_print(idprint_chat"You recived an Deagle with 1 bullet! (5%% chance)");
                    }
                }
                case 
7:
                {
                    if(
random_num(0100) <= 10)
                    {
                        
give_item(id"weapon_usp");
                        
cs_set_weapon_ammo(find_ent_by_owner(1"weapon_usp"id), 1);
                        
client_print(idprint_chat"You recived an Usp with 1 bullet! (10%% chance)");
                    }
                }
                case 
8:
                {
                    if(
random_num(0100) <= 5)
                    {
                        
give_item(id"weapon_scout");
                        
cs_set_weapon_ammo(find_ent_by_owner(1"weapon_scout"id), 1);
                        
client_print(idprint_chat"You recived an Scout with 1 bullets! (5%% chance)");
                    }
                }
                case 
9:
                {
                    if(
random_num(0100) <= 35)
                    {
                        
set_user_armor(id100);
                        
client_print(idprint_chat"You recived 100 armor! (35%% chance)");
                    }
                }
                case 
10:
                {
                    if(
random_num(0100) <= 20)
                    {
                        
set_user_health(id115);
                        
client_print(idprint_chat"You recived 115 health! (20%% chance)");
                    }
                }
            }
        }
    }

tepAse is offline
TitANious
Veteran Member
Join Date: Feb 2009
Location: Denmark
Old 07-25-2009 , 15:02   Re: [Help] Weapon Chance
Reply With Quote #2

You should have an other switch
__________________
I dislike this.

"A sneeze never comes alone!" <-- Important to remember.
TitANious is offline
Send a message via MSN to TitANious
tepAse
Junior Member
Join Date: Jun 2009
Old 07-25-2009 , 15:12   Re: [Help] Weapon Chance
Reply With Quote #3

Ok, think you could fix it? My first plugin so ^^
tepAse is offline
TitANious
Veteran Member
Join Date: Feb 2009
Location: Denmark
Old 07-25-2009 , 15:54   Re: [Help] Weapon Chance
Reply With Quote #4

I can't do it on this pc, sorry.
__________________
I dislike this.

"A sneeze never comes alone!" <-- Important to remember.
TitANious is offline
Send a message via MSN to TitANious
tepAse
Junior Member
Join Date: Jun 2009
Old 07-25-2009 , 19:08   Re: [Help] Weapon Chance
Reply With Quote #5

No problem! Thanks for your help anyway!
tepAse is offline
TitANious
Veteran Member
Join Date: Feb 2009
Location: Denmark
Old 07-26-2009 , 06:22   Re: [Help] Weapon Chance
Reply With Quote #6

Try use ham, and register like:

RegisterHam( Ham_Spawn, "player", "fw_spawn" )
__________________
I dislike this.

"A sneeze never comes alone!" <-- Important to remember.
TitANious is offline
Send a message via MSN to TitANious
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 07-26-2009 , 15:04   Re: [Help] Weapon Chance
Reply With Quote #7

Take a look at your switch statement, get_user_team can only return 3 values. Look at the func page I showed you. I am sorry to not give a proper response, I am writing from my phone. edit: Titan, that wont help at all, that will only hook when the player spawns. Round start works fine. The code is pretty okay, you could remove is_user_connected and just use alive, because if the dude is alive, then he's connected.
Damn, this looks awful. I am sorry.
__________________
Achievements API - a simple way for you to create your OWN custom achievements!

Last edited by Xellath; 07-26-2009 at 15:21.
Xellath is offline
TitANious
Veteran Member
Join Date: Feb 2009
Location: Denmark
Old 07-26-2009 , 16:17   Re: [Help] Weapon Chance
Reply With Quote #8

I can maybe help rewrite it a bit tomorrow
__________________
I dislike this.

"A sneeze never comes alone!" <-- Important to remember.
TitANious is offline
Send a message via MSN to TitANious
TitANious
Veteran Member
Join Date: Feb 2009
Location: Denmark
Old 07-27-2009 , 06:35   Re: [Help] Weapon Chance
Reply With Quote #9

Try this:
PHP Code:
#include <amxmodx>
#include <cstrike>
#include <fun>
#include <engine>

#define PLUGIN    "Weapon Chance"
#define AUTHOR    "FaktuM"
#define VERSION    "1.0"

new szName32 ];

new 
bool:GotChance33 ]

public 
plugin_init( )
{
    
register_pluginPLUGINVERSIONAUTHOR );
    
    
register_event"HLTV""eventRoundStart""a""1=0""2=0" );
}

public 
eventRoundStartid )
{
    
set_task5.0"WeaponChance" );
    
GotChanceid ] = false;
}

public 
WeaponChanceid )
{
    if( 
GotChanceid ] == true )
        return 
PLUGIN_HANDLED
        
    get_user_name
idszName31 );
    
    if( 
is_user_connectedid ) )
    {
        
        if( 
random_num0100 ) <= 20 )
        {
            if( 
GotChanceid ] == true )
                return 
PLUGIN_HANDLED
                
            give_item
id"weapon_hegrenade" );
            
client_printidprint_chat"You got a HE! (20%% chance)" );
            
GotChanceid ] = true
                
        
}
        if( 
random_num0100 ) <= 30 )
        {
            if( 
GotChanceid ] == true )
                return 
PLUGIN_HANDLED
                
            give_item
id"weapon_flashbang" );
            
client_printidprint_chat"You got a flashbang! (30%% chance)" );
            
GotChanceid ] = true
        
}
        if( 
random_num0100 ) <= )
        {
            if( 
GotChanceid ] == true )
                return 
PLUGIN_HANDLED
                
            give_item
id"weapon_awp" );
            
cs_set_weapon_ammofind_ent_by_owner2"weapon_awp"id ), );
            
client_printidprint_chat"You got an awp with 2 bullets! (1%% chance)" );
            
            
client_print0print_chat"[Weapon Chance] %s has recived an awp with two bullets, aware!"szName );
            
GotChanceid ] = true
        
}
        if( 
random_num0100 ) <= )
        {
            if( 
GotChanceid ] == true )
                return 
PLUGIN_HANDLED
                
            set_user_health
id150 );
            
client_printidprint_chat"You recived 150 health! (5%% chance)" );
            
GotChanceid ] = true
        
}
        if( 
random_num0100 ) <= 10 )
        {
            if( 
GotChanceid ] == true )
                return 
PLUGIN_HANDLED
                
            give_item
id"weapon_fiveseven" );
            
cs_set_weapon_ammofind_ent_by_owner1"weapon_fiveseven"id ), );
            
client_printidprint_chat"You recived an Fiveseven with 1 bullet! (10%% chance)" );
            
GotChanceid ] = true
        
}
        if( 
random_num0100 ) <= )
        {
            if( 
GotChanceid ] == true )
                return 
PLUGIN_HANDLED
                
            give_item
id"weapon_deagle" );
            
cs_set_weapon_ammofind_ent_by_owner1"weapon_deagle"id ), );
            
client_printidprint_chat"You recived an Deagle with 1 bullet! (5%% chance)" );
            
GotChanceid ] = true
        
}
        if( 
random_num0100 ) <= 10 )
        {
            if( 
GotChanceid ] == true )
                return 
PLUGIN_HANDLED
                
            give_item
id"weapon_usp" );
            
cs_set_weapon_ammofind_ent_by_owner1"weapon_usp"id ), );
            
client_printidprint_chat"You recived an Usp with 1 bullet! (10%% chance)" );
            
GotChanceid ] = true
        
}
        if( 
random_num0100 ) <= )
        {
            if( 
GotChanceid ] == true )
                return 
PLUGIN_HANDLED
                
            give_item
id"weapon_scout" );
            
cs_set_weapon_ammofind_ent_by_owner1"weapon_scout"id ), );
            
client_printidprint_chat"You recived an Scout with 1 bullets! (5%% chance)" );
            
GotChanceid ] = true
        
}
        if(
random_num0100 ) <= 35 )
        {
            if( 
GotChanceid ] == true )
                return 
PLUGIN_HANDLED
                
            set_user_armor
id100 );
            
client_printidprint_chat"You recived 100 armor! (35%% chance)" );
            
GotChanceid ] = true
        
}
        if( 
random_num0100 ) <= 20 )
        {
            if( 
GotChanceid ] == true )
                return 
PLUGIN_HANDLED
                
            set_user_health
id115 );
            
client_printidprint_chat"You recived 115 health! (20%% chance)" );
            
GotChanceid ] = true
        
}
    }
    return 
PLUGIN_CONTINUE

__________________
I dislike this.

"A sneeze never comes alone!" <-- Important to remember.
TitANious is offline
Send a message via MSN to TitANious
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 07-27-2009 , 07:19   Re: [Help] Weapon Chance
Reply With Quote #10

You added a useless bool and whitespace..?
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath 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 18:18.


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