AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Help] Weapon Chance (https://forums.alliedmods.net/showthread.php?t=98452)

tepAse 07-25-2009 14:17

[Help] Weapon Chance
 
I've tried to make an Weapon Chance plugin, i get no error's but it doesnt give out items ingame.. :cry: 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)");
                    }
                }
            }
        }
    }



TitANious 07-25-2009 15:02

Re: [Help] Weapon Chance
 
You should have an other switch :)

tepAse 07-25-2009 15:12

Re: [Help] Weapon Chance
 
Ok, think you could fix it? :) My first plugin so ^^

TitANious 07-25-2009 15:54

Re: [Help] Weapon Chance
 
I can't do it on this pc, sorry. :(

tepAse 07-25-2009 19:08

Re: [Help] Weapon Chance
 
No problem! Thanks for your help anyway! :)

TitANious 07-26-2009 06:22

Re: [Help] Weapon Chance
 
Try use ham, and register like:

RegisterHam( Ham_Spawn, "player", "fw_spawn" )

Xellath 07-26-2009 15:04

Re: [Help] Weapon Chance
 
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. :crab: 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. :mrgreen:

TitANious 07-26-2009 16:17

Re: [Help] Weapon Chance
 
I can maybe help rewrite it a bit tomorrow :)

TitANious 07-27-2009 06:35

Re: [Help] Weapon Chance
 
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



Xellath 07-27-2009 07:19

Re: [Help] Weapon Chance
 
You added a useless bool and whitespace..?


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

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