AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   sometimes this plugin works ,sometimes not ? (https://forums.alliedmods.net/showthread.php?t=183143)

elle 04-18-2012 00:34

sometimes this plugin works ,sometimes not ?
 
Hi
I want to creat a plugin works with player and zbot that

+ give VIP Free Armor+Helm + 90 pistols ammo + grenade
( immediately at the first round and all later rounds )
+ 20 hp and extra 1 score when VIP kill a player
+ extra 1 score when vip escape



here is the code

Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <hamsandwich>

#define PLUGIN_NAME    "RVip"
#define PLUGIN_VERSION    "1.0"
#define PLUGIN_AUTHOR    "Leech"

new g_hamczbots, g_vipspawn, g_roundstart
new cvar_hp_kill, cvar_hp_hs, cvar_max_hp
new g_vip[33]

public plugin_init()
{
    register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)

    register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
    register_logevent("logevent_round_end", 2, "1=Round_End")

    RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
    RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
    cvar_hp_kill = register_cvar("amx_vip_hp", "15")
    cvar_hp_hs = register_cvar("amx_vip_hp_hs", "30")
    cvar_max_hp = register_cvar("amx_vip_max_hp", "100")
}

public client_putinserver(id)
{
    if (g_hamczbots) return
    if (!is_user_bot(id)) return
    set_task(0.1, "register_ham_czbots", id)
}

public register_ham_czbots(id)
{
    if (g_hamczbots || !is_user_connected(id)) return

    if (!is_user_bot(id)) return
    RegisterHamFromEntity(Ham_Killed, id, "fw_PlayerKilled")
    RegisterHamFromEntity(Ham_Spawn, id, "fw_PlayerSpawn_Post", 1)

    g_hamczbots = true
    if (is_user_alive(id)) fw_PlayerSpawn_Post(id)
}

public Event_NewRound()
{
    g_roundstart = true

    new num = get_alive()
    if (num<=0) return

    for (new i=0;i<33;i++)
    {
        g_vip[i] = false
        g_vipspawn = false
    }
    new id = get_random_alive(random_num(1, num))
    g_vip[id] = true
    g_vipspawn = true
}

get_alive()
{
    static alive, id
    alive = 0
    for (id=1;id<=33;id++) if (is_user_alive(id)) alive++

    return alive
}

get_random_alive(n)
{
    static alive, id
    alive = 0

    for (id=1;id<=33;id++)
    {
        if (is_user_alive(id)) alive++
        if (alive == n) return id
    }
    return -1
}

public logevent_round_end()
{
    g_roundstart = false
    for (new id=0;id<33;id++)
    {
        if (is_user_alive(id) && g_vip[id])
        {
            g_vip[id] = false
            g_vipspawn = false
            set_user_frags(id, get_user_frags(id)+1)
        }
    }
}

public fw_PlayerKilled(victim, attacker, shouldgib)
{
    if (g_vip[victim]) g_vip[victim] = false
    if (g_vip[attacker] && is_user_connected(victim))
    {
        new hp = get_user_health(attacker)
        new add, target, body
        get_user_aiming(attacker, target, body, 9999)

        if (body==1)    add = get_pcvar_num(cvar_hp_hs)
        else        add = get_pcvar_num(cvar_hp_kill)

        if (get_pcvar_num(cvar_max_hp) < hp+add)
            set_user_health(attacker, get_pcvar_num(cvar_max_hp))
        else    set_user_health(attacker, get_user_health(attacker)+add)
        set_user_frags(attacker, get_user_frags(attacker)+1)
    }
}

public fw_PlayerSpawn_Post(id)
{
    if (!is_user_alive(id)) return
    if (!g_vipspawn && g_roundstart)
    {
        new num = get_alive()
        if (num<=0) return
        new i = get_random_alive(random_num(1, num))

        g_vip[i] = true
        g_vipspawn = true
    }
    remove_task(id)
    set_task(1.0, "vip_spawn", id)
}

public vip_spawn(id)
{
    if (!is_user_alive(id)) return
    if (!g_vip[id]) return

    give_item(id, "weapon_hegrenade")
    give_item(id, "weapon_flashbang")
    give_item(id, "weapon_flashbang")
    give_item(id, "weapon_smokegrenade")

    if (cs_get_user_team(id)==CS_TEAM_T)
        cs_set_user_bpammo(id, CSW_GLOCK18, cs_get_user_bpammo(id,CSW_GLOCK18)+90)
    if (cs_get_user_team(id)==CS_TEAM_CT)
        cs_set_user_bpammo(id, CSW_USP, cs_get_user_bpammo(id,CSW_USP)+90)
    cs_set_user_armor(id, 100, CS_ARMOR_VESTHELM)
    new name[32]
    get_user_name(id, name, 31)
    client_print(0, print_chat, "%s is vip", any:name)
}

sometimes it works, but usually it does not

sometimes i do not get extra ammo (still have 12 ammo) and Kevlar 200, somtimes i get 100 ammo and Kevlar 100 a many times even when the giving ammo Function works (i have 100 ammo), but the + score, and + hp functions not works

I enable debugging mode , but no problem 's reported


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

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