Raised This Month: $51 Target: $400
 12% 

[L4D2] Player Join Item Giver Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MasterMind420
BANNED
Join Date: Nov 2010
Old 12-15-2016 , 16:12   [L4D2] Player Join Item Giver Help
Reply With Quote #1

ok so i'm having an issue giving items to all players when they spawn/join the server. The code as is works but only fires for me, i've tried using other admins as well and same always happens, only I receive the pistol and machete. Doesn't matter if i am first to join the server or midway through. I'm stumped and could use some input on this. I thought maybe the GiveWeapon function was the problem but I don't know. Any help would be appreciated. I've coded this several different ways and always have the same result. Other players get nothing. Not even the message for them getting an item appears. It's very odd because as its coded it should fire for all players spawning.

Code:
#pragma semicolon 1 //REQUIRE SEMICOLONS AT THE END OF LINES
//#pragma newdecls required //FORCES THE USE OF NEW SYNTAX

#include <sourcemod>
#include <sdktools>

Handle:GiveTimer[MAXPLAYERS+1] = INVALID_HANDLE;

public Plugin:myinfo =
{
    name = "",
    author = "MasterMind420",
    description = "",
    version = "1.0",
    url = ""
}

public OnPluginStart()
{
    /*EVENT HOOKS*/
    HookEvent("round_start", Event_Round_Start);
    HookEvent("player_spawn", Event_Player_Spawn); //, EventHookMode_Post);
}

public Action:Event_Round_Start(Handle:event, const String:name[], bool:dont_broadcast)
{
    new client = GetClientOfUserId(GetEventInt(event, "userid"));

    if (IsSurvivor(client))
    {
        if (GiveTimer[client] != INVALID_HANDLE)
        {
            PrintToChatAll("Killed Timer In Spawn Event"); //DEBUG
            CloseHandle(GiveTimer[client]);
            GiveTimer[client] = INVALID_HANDLE;
        }
    }
}

public Action:Event_Player_Spawn(Handle:event, const String:name[], bool:dont_broadcast)
{
    new client = GetClientOfUserId(GetEventInt(event, "userid"));

    if (IsSurvivor(client))
        GiveTimer[client] = CreateTimer(3.0, GiveWeaponDelay, client, TIMER_FLAG_NO_MAPCHANGE);
}

public Action:GiveWeaponDelay(Handle:timer, any:client)
{
    if (IsSurvivor(client))
    {
        GiveTimer[client] = INVALID_HANDLE;
        GivePlayerWeapon(client);
    }
    return Plugin_Handled;
}

GivePlayerWeapon(client)
{
    if (IsSurvivor(client))
    {
        decl pistol;
        pistol = GetPlayerWeaponSlot(client, 1);

        decl melee;
        melee = GetPlayerWeaponSlot(client, 6);

        decl String:sWeapon[32];
        GetEntityClassname(pistol, sWeapon, sizeof(sWeapon));

        if (pistol != -1 && StrEqual(sWeapon, "weapon_pistol", true) && !GetEntProp(pistol, Prop_Send, "m_hasDualWeapons"))
        {
            new String:ClientName[32];
            GetClientName(client, ClientName, sizeof(ClientName));

            GiveWeapon(client, "pistol");
            PrintToChat(client, "%s was given a pistol", ClientName);
        }

        if (melee == -1)
        {
            new String:ClientName[32];
            GetClientName(client, ClientName, sizeof(ClientName));

            GiveWeapon(client, "machete");
            PrintToChat(client, "%s was given a machete", ClientName);
        }
    }
}

GiveWeapon(client, String:Item[32])
{
    new flags = GetCommandFlags("give");
    SetCommandFlags("give", flags & ~FCVAR_CHEAT);
    FakeClientCommand(client, "give %s", Item);
    SetCommandFlags("give", flags|FCVAR_CHEAT);
}

stock bool:IsSurvivor(client)
{
    return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && IsPlayerAlive(client);
}

Last edited by MasterMind420; 12-15-2016 at 16:16.
MasterMind420 is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 12-15-2016 , 18:03   Re: [L4D2] Player Join Item Giver Help
Reply With Quote #2

Aren't there other plugins that does this already like the Round Start Item Giver plugin?
cravenge is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 12-15-2016 , 18:25   Re: [L4D2] Player Join Item Giver Help
Reply With Quote #3

Quote:
Originally Posted by cravenge View Post
Aren't there other plugins that does this already like the Round Start Item Giver plugin?
Yes however this is for my simplified needs and most of this code was taken directly from that plugin, oddly enough if you look at round start item giver code, this is identical yet it doesn't work as it should. There are problems with round start item giver plugin i was trying to eliminate in this...wouldn't you say its odd that this code doesn't fire for all clients just looking at it? It should but doesn't...I will try using round start item giver just to see if it gives items to all clients that join, but I suspect it won't. If it does then its a problem on my server...
MasterMind420 is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 12-15-2016 , 18:37   Re: [L4D2] Player Join Item Giver Help
Reply With Quote #4

Which reminds me, I fixed some bugs in it and I'm posting it now.
cravenge is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 12-15-2016 , 18:38   Re: [L4D2] Player Join Item Giver Help
Reply With Quote #5

Quote:
Originally Posted by cravenge View Post
Which reminds me, I fixed some bugs in it and I'm posting it now.
good man, i'll take a look at it, thanks...
MasterMind420 is offline
cravenge
Veteran Member
Join Date: Nov 2015
Location: Chocolate Factory
Old 12-15-2016 , 19:26   Re: [L4D2] Player Join Item Giver Help
Reply With Quote #6

Here it is: Updated version
cravenge is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 12-15-2016 , 21:12   Re: [L4D2] Player Join Item Giver Help
Reply With Quote #7

thanks, yah i checked it out, didn't actually use it because i don't use l4downtown, but i modified my code to match yours for the item spawning and same issue. You may wanna check with a chat or hint message to make sure its giving items to all players, I seriously suspect it isn't...
MasterMind420 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 04:15.


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