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

[L4D2] Get Ghost Spawntime


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kusber
New Member
Join Date: Oct 2020
Old 10-16-2020 , 10:38   [L4D2] Get Ghost Spawntime
Reply With Quote #1

Hello all,

I'm new in Sourcemod Scripting so I'm sorry for this noob question.

I'm trying to get the ghost spawntime and excute some code if clients spawntime is under 4 seconds.

Here is my code:

PHP Code:
#include <sourcemod>

#define TEAM_INFECTED    3

public onPluginStart()
{
    
HookEvent("ghost_spawn_time",event_ghost_spawn_timeEventHookMode_Post); 
}

public 
event_ghost_spawn_time(Handle:event, const String:name[], bool:dontBroadcast)
{
    
    new 
client GetClientOfUserId(GetEventInt(event,"userid"));
    new 
spawntime GetEventFloat(event,"spawntime");
    if (
IsHumanPlayer(client) && IsPlayerGhost && GetClientTeam(client) == && spawntime 4)
    {
        
// DoSomeThing
    
}

But that isn't working. ;'(
Kusber is offline
devilesk
Junior Member
Join Date: May 2019
Old 10-16-2020 , 10:56   Re: [L4D2] Get Ghost Spawntime
Reply With Quote #2

Code:
new spawntime = GetEventFloat(event,"spawntime");
spawntime should be a float.

Code:
if (IsHumanPlayer(client) && IsPlayerGhost && GetClientTeam(client) == 3 && spawntime < 4)
I don't know what IsHumanPlayer does and IsPlayerGhost doesn't look right. Is it a variable or supposed to be a function call? Anyway, here's how I'd write it:

Code:
if (client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client) && GetClientTeam(client) == 3 && spawntime < 4.0)
devilesk is offline
Kusber
New Member
Join Date: Oct 2020
Old 10-19-2020 , 09:34   Re: [L4D2] Get Ghost Spawntime
Reply With Quote #3

Thank you,

I tried that:

PHP Code:
if (client && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client) && GetClientTeam(client) == && spawntime 4.0
But my Code will not excute
Kusber is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-19-2020 , 14:19   Re: [L4D2] Get Ghost Spawntime
Reply With Quote #4

I don't know much about how this event works, but maybe it fires only once when the player becomes ghost.

Anyway try like this:

PHP Code:
#include <sourcemod>

#pragma semicolon 1
#pragma newdecls required

#define TEAM_INFECTED    3

public void OnPluginStart()
{
    
HookEvent("ghost_spawn_time"event_ghost_spawn_time);
}

public 
void event_ghost_spawn_time(Event event, const char[] namebool dontBroadcast)
{

    
int client GetClientOfUserId(event.GetInt("attacker"));
    
int spawntime event.GetInt("spawntime");

    
PrintToChatAll("client %N | time %i"clientspawntime);

    if (
<= client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client) && GetClientTeam(client) == && spawntime 4)
    {
        
PrintToChatAll("Do Something");
    }

If that doesn't fire every second, then you may need to create a timer to make the "countdown"
__________________

Last edited by Marttt; 10-19-2020 at 14:20.
Marttt is offline
devilesk
Junior Member
Join Date: May 2019
Old 10-19-2020 , 14:45   Re: [L4D2] Get Ghost Spawntime
Reply With Quote #5

I went ahead and actually tested it and found another issue. onPluginStart needs to be OnPluginStart or else it won't fire.

Also, as Marttt mentioned, the event only fires once when you become a ghost. So if you spawn in and your spawntime isn't less than 4s it won't work. Testing alone worked for me, because I was getting a 3s respawn time but I know with more people the respawn time will be higher.

This is the full code I tested and it worked:
Code:
#include <sourcemod>

#define TEAM_INFECTED    3

public OnPluginStart()
{
    HookEvent("ghost_spawn_time",event_ghost_spawn_time, EventHookMode_Post); 
}

public event_ghost_spawn_time(Handle:event, const String:name[], bool:dontBroadcast)
{
    
    new client = GetClientOfUserId(GetEventInt(event,"userid"));
    new Float:spawntime = GetEventFloat(event,"spawntime");
    if (client > 0 && client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client) && GetClientTeam(client) == 3 && spawntime < 4.0)
    {
        PrintToChatAll("%i spawned. spawntime %f", client, spawntime);
    }
}
devilesk is offline
canadianjeff
BANNED
Join Date: Sep 2016
Old 10-23-2020 , 12:32   Re: [L4D2] Get Ghost Spawntime
Reply With Quote #6

this sounds like an anticheat detection method could you maybe put this in sourcemod anticheat??
canadianjeff is offline
Kusber
New Member
Join Date: Oct 2020
Old 10-24-2020 , 09:09   Re: [L4D2] Get Ghost Spawntime
Reply With Quote #7

Quote:
Originally Posted by Marttt View Post
I don't know much about how this event works, but maybe it fires only once when the player becomes ghost.

Anyway try like this:

PHP Code:
#include <sourcemod>

#pragma semicolon 1
#pragma newdecls required

#define TEAM_INFECTED    3

public void OnPluginStart()
{
    
HookEvent("ghost_spawn_time"event_ghost_spawn_time);
}

public 
void event_ghost_spawn_time(Event event, const char[] namebool dontBroadcast)
{

    
int client GetClientOfUserId(event.GetInt("attacker"));
    
int spawntime event.GetInt("spawntime");

    
PrintToChatAll("client %N | time %i"clientspawntime);

    if (
<= client <= MaxClients && IsClientInGame(client) && !IsFakeClient(client) && GetClientTeam(client) == && spawntime 4)
    {
        
PrintToChatAll("Do Something");
    }

If that doesn't fire every second, then you may need to create a timer to make the "countdown"
Yep, that is working Thank you!
Kusber is offline
canadianjeff
BANNED
Join Date: Sep 2016
Old 10-25-2020 , 16:59   Re: [L4D2] Get Ghost Spawntime
Reply With Quote #8

is no one gonna suggest this code be added to some kind of anticheat system I keep running into this problem even on valves stupid official servers
canadianjeff is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-26-2020 , 12:01   Re: [L4D2] Get Ghost Spawntime
Reply With Quote #9

@canadianjeff

Probably the help he asked for is not for some kind of anti-cheat, maybe its just a warning to the player that he will spawn in "4" seconds, or do some kick/slay if it doesn't move, for example, if you have issues with this, I recommend opening a new thread in the forum asking for help, instead using this one.
__________________

Last edited by Marttt; 10-26-2020 at 12:01.
Marttt is offline
Reply


Thread Tools
Display Modes

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 18:11.


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