AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [L4D2] Get Ghost Spawntime (https://forums.alliedmods.net/showthread.php?t=327913)

Kusber 10-16-2020 11:38

[L4D2] Get Ghost Spawntime
 
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. ;'(

devilesk 10-16-2020 11:56

Re: [L4D2] Get Ghost Spawntime
 
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)

Kusber 10-19-2020 10:34

Re: [L4D2] Get Ghost Spawntime
 
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 :(

Marttt 10-19-2020 15:19

Re: [L4D2] Get Ghost Spawntime
 
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"

devilesk 10-19-2020 15:45

Re: [L4D2] Get Ghost Spawntime
 
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);
    }
}


canadianjeff 10-23-2020 13:32

Re: [L4D2] Get Ghost Spawntime
 
this sounds like an anticheat detection method could you maybe put this in sourcemod anticheat??

Kusber 10-24-2020 10:09

Re: [L4D2] Get Ghost Spawntime
 
Quote:

Originally Posted by Marttt (Post 2721922)
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! :up:

canadianjeff 10-25-2020 17:59

Re: [L4D2] Get Ghost Spawntime
 
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

Marttt 10-26-2020 13:01

Re: [L4D2] Get Ghost Spawntime
 
@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.


All times are GMT -4. The time now is 17:10.

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