AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Function on player spawn, how to set index? (https://forums.alliedmods.net/showthread.php?t=306155)

GoldNux 03-18-2018 19:24

Function on player spawn, how to set index?
 
This plugin is meant to give you a weapon when you respawn, but it gives you a new weapon any time someone respawns. How do I make it so it only does it for the person spawning?

Thanks!

Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <hamsandwich> #include <fun> #define PLUGIN "gn_impulser" #define VERSION "0.1" #define AUTHOR "GoldNux" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1)     register_cvar("gn_impulse", "0") } public fwHamPlayerSpawnPost(id) {     if (is_user_alive(id))     {         if (!get_cvar_num("gn_impulse"))         {             return PLUGIN_CONTINUE         }         new players[32]         new playercount         get_players(players, playercount)         new i         for (i=0; i<playercount; i++)         {             giveWeapons(players[i])         }     }     return PLUGIN_CONTINUE } public giveWeapons(id) {     if (cs_get_user_team(id) == CS_TEAM_T)     {            cs_set_user_armor(id, 100, CS_ARMOR_VESTHELM)         give_item(id, "weapon_ak47")         cs_set_user_bpammo(id, CSW_SCOUT, 90)         give_item(id, "weapon_hegrenade")         client_cmd(id, "lastinv")     }     if (cs_get_user_team(id) == CS_TEAM_CT)     {         cs_set_user_armor(id, 100, CS_ARMOR_VESTHELM)         give_item(id, "weapon_m4a1")         cs_set_user_bpammo(id, CSW_AUG, 90)         cs_set_user_defuse(id, 1)         give_item(id, "weapon_hegrenade")         client_cmd(id, "lastinv")     } }

JusTGo 03-18-2018 19:43

Re: Function on player spawn, how to set index?
 
change :

PHP Code:

public fwHamPlayerSpawnPost(id)
{
    if (
is_user_alive(id))
    {
        if (!
get_cvar_num("gn_impulse"))
        {
            return 
PLUGIN_CONTINUE
        
}

        new 
players[32]
        new 
playercount
        get_players
(playersplayercount)

        new 
i
        
for (i=0i<playercounti++)
        {
            
giveWeapons(players[i])
        }
    }

    return 
PLUGIN_CONTINUE


to:

PHP Code:

public fwHamPlayerSpawnPost(id)
{
    if (
is_user_alive(id))
    {
        if (!
get_cvar_num("gn_impulse"))
        {
            return 
PLUGIN_CONTINUE
        
}

        
giveWeapons(id)
    }

    return 
PLUGIN_CONTINUE



Bugsy 03-18-2018 20:30

Re: Function on player spawn, how to set index?
 
PHP Code:

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

#define PLUGIN "gn_impulser"
#define VERSION "0.1"
#define AUTHOR "GoldNux"

new g_pImpulse;

public 
plugin_init()
{
    
register_pluginPLUGIN VERSION AUTHOR );
    
RegisterHamHam_Spawn "player""fwHamPlayerSpawnPost" );
    
g_pImpulse register_cvar"gn_impulse" "0" );
}

public 
fwHamPlayerSpawnPostid )
{
    if ( 
is_user_aliveid ) && get_pcvar_numg_pImpulse ) )
    {
        
giveWeaponsid );
    }


public 
giveWeaponsid )
{
    new 
CsTeams:ctTeam cs_get_user_teamid );
    
    
give_itemid , ( ctTeam == CS_TEAM_T ) ? "weapon_ak47" "weapon_m4a1" );
    
cs_set_user_bpammoid , ( ctTeam == CS_TEAM_T ) ? CSW_SCOUT CSW_AUG 90 );
    
give_itemid "weapon_hegrenade" );
    
cs_set_user_armorid 100 CS_ARMOR_VESTHELM );
    
client_cmdid "lastinv" );




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

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