AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with WeaponChance (https://forums.alliedmods.net/showthread.php?t=164142)

lagaar 08-07-2011 18:13

Help with WeaponChance
 
Hello!, How are you? I'm fine... I have a blockmaker and i would like create a WeaponChance block. This block, would select randomly a weapon and gives this from the player.

I hope you can help me.

Thanks!

Sorry for my bad english

SpeeDeeR 08-07-2011 18:26

Re: Help with WeaponChance
 
Create and array with all weapon names and give_item() a random array cell.

lagaar 08-08-2011 11:25

Re: Help with WeaponChance
 
Can you tell me an example?

SpeeDeeR 08-08-2011 11:32

Re: Help with WeaponChance
 
PHP Code:

new const array[] = 
{
    
"weapon_m3",
    
"weapon_m4a1",
    
"weapon_awp"
}

public function(
id)
{
    
give_item(id,array[random(charsmax(array))])



Exolent[jNr] 08-08-2011 11:35

Re: Help with WeaponChance
 
Quote:

Originally Posted by lagaar (Post 1528260)
Can you tell me an example?

He doesn't understand weapon chance blocks.

What you could do is this:

Code:
actionWeaponChance(id) {     // when player steps on block     // check cooldown if you want         // random chance for getting a weapon     if( random(100) < 30 )     {         // player beat the 30% chance for weapon                 // give the weapon (in this example, ak47)         new ent = give_item(id, "weapon_ak47");                 // set the weapon's ammo         cs_set_weapon_ammo(ent, 1); // 1 bullet in clip                 // set the backpack ammo         cs_set_user_bpammo(ent, CSW_AK47, 0); // no bp ammo     } }

SpeeDeeR 08-08-2011 11:43

Re: Help with WeaponChance
 
Quote:

Originally Posted by lagaar (Post 1527864)
Hello!, How are you? I'm fine...i would like create a WeaponChance block

Ooh... now I got it. Sorry.

lagaar 08-08-2011 11:57

Re: Help with WeaponChance
 
Thanks for all! Here one example of the block.

PHP Code:

actionWeaponChance(id)
{    
        if (
is_user_alive(id) && !WeaponChanceUser[id] && get_user_team(id) == 1)     
    {
        
get_user_name(idweaponname32);
        switch (
random_num(02)) 
        { 
            case 
0show_hudmessage(0"[WeaponChance Block] A %s le toco una p228"weaponname);
        
give_item(id"weapon_p228");
        
cs_set_weapon_ammo(find_ent_by_owner(1"weapon_p228"id), 2);
            case 
1show_hudmessage(0"[WeaponChance Block] A %s le toco una Scout"weaponname);
        
give_item(id"weapon_scout");
        
cs_set_weapon_ammo(find_ent_by_owner(1"weapon_scout"id), 1);
            case 
2show_hudmessage(0"[WeaponChance Block] A %s le toco una He"weaponname);
        
give_item(id"weapon_hegrenade");
        
cs_set_weapon_ammo(find_ent_by_owner(1"weapon_hegrenade"id), 2);
        }  
    }


It's okey?

Exolent[jNr] 08-08-2011 11:58

Re: Help with WeaponChance
 
Grenades don't have ammo.
If you want to give more than 1, use BP ammo for the player.

And I guess SpeeDeeR was right the first time.
First time I've seen a weapon chance block like this.


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

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