This site is a testing version, but all data is shared with the live forum.


Raised This Month: $ Target: $400
 0% 

Solved Hi, is it possible to change this code from a kill function to a respawn function?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hl2dmgamer
Junior Member
Join Date: Dec 2023
Old 12-11-2023 , 15:06   Hi, is it possible to change this code from a kill function to a respawn function?
Reply With Quote #1

Hi, is it possible to change this code from a slap function to a respawn function?
Thank you
PHP Code:
#include <sdktools>
#include <simple_colors>
#include <sourcemod>
#include <halflife>
#include <sdkhooks>
#include <sdktools_hooks>
#include <sdktools_stocks>


#pragma semicolon 1
#pragma newdecls required

int g_iCampTime;
int g_iSlapDamage;

float g_fRadius;
//int g_iBeamSprite = -1;
//int g_iHaloSprite = -1;
float g_fLastPos[MAXPLAYERS 1][3];
float g_fSpawnEyeAng[MAXPLAYERS 1][3];

Handle g_hTimerChecker[MAXPLAYERS 1];

int g_iCampCount[MAXPLAYERS 1];

#define            NAME         "antiCBot"
#define            AUTHOR        "TRON"
#define            VERSION        "4.0"

public Plugin myinfo =

    
name    NAME,
    
author    AUTHOR,
    
version    VERSION,
};

public 
void OnPluginStart()
{
    
HookEvent("round_end"Event_RoundEndEventHookMode_Pre);
    
HookEvent("player_spawn"Event_PlayerSpawnEventHookMode_Post);
    
HookEvent("player_death"Event_PlayerDeath);

    
LoadTranslations("Bot_AntiCamp.phrases");
    
LoadSettings();
}

public 
void OnMapStart()
{
    
//g_iBeamSprite = PrecacheModel("materials/sprites/laserbeam.vmt", true);
    //g_iHaloSprite = PrecacheModel("materials/sprites/halo01.vmt", true);
    
PrecacheSound("buttons/button1.wav"true);

   
LoadSettings();
}

void LoadSettings()
{
    
char sBuffer[256];
    
BuildPath(Path_SMsBuffersizeof(sBuffer), "configs/Bot_AntiCamp.cfg");

    if(!
FileExists(sBuffer))
    {
        
SetFailState("File doesnt exist: %s"sBuffer);
        return;
    }

    
KeyValues kv = new KeyValues("Configs1");

    if(!
kv.ImportFromFile(sBuffer))
    {
        
delete kv;
        
SetFailState("File not found %s!"sBuffer);
        return;
    }

    
g_iCampTime kv.GetNum("camp_time");
    
g_iSlapDamage kv.GetNum("slap_damage");
    
g_fRadius kv.GetFloat("radius");

    
delete kv;
}

public 
void OnClientDisconnect(int iClient)
{
    
DeleteTimer(iClient);
    
g_iCampCount[iClient] = 0;
}

public 
Action Event_RoundEnd(Event hEventchar[] sEvNamebool bDontBroadcast)
{
    for(
int i 1<= MaxClientsi++)
    {
        if(
IsFakeClient(i))
        {
            
DeleteTimer(i);
            
g_iCampCount[i] = 0;
        }
    }
}

public 
Action Event_PlayerDeath(Event hEventchar[] sEvNamebool bDontBroadcast)
{
    
int iClient GetClientOfUserId(hEvent.GetInt("userid"));

    
DeleteTimer(iClient);
}

public 
Action Event_PlayerSpawn(Event hEventchar[] sEvNamebool bDontBroadcast)
{
    
//if(IsWarmup()) return;

    
int iClient GetClientOfUserId(hEvent.GetInt("userid"));

    
GetClientAbsOrigin(iClientg_fLastPos[iClient]);
    
GetClientAbsOrigin(iClientg_fSpawnEyeAng[iClient]);

    
DeleteTimer(iClient);
    
g_hTimerChecker[iClient] = CreateTimer(2.0Timer_CheckerGetClientUserId(iClient), TIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action Timer_Checker(Handle hTimerany iClientUserId)
{
    
int iClient GetClientOfUserId(iClientUserId);

    if(!
iClient || !IsPlayerAlive(iClient)|| !IsFakeClient(iClient))
    {
        
g_hTimerChecker[iClient] = null;
        return 
Plugin_Stop;
    }

    if(
g_hTimerChecker[iClient] == null) return Plugin_Stop;

    if(
IsCamping(iClient)) g_iCampCount[iClient] += 2;
    else 
g_iCampCount[iClient] = 0;

    if(
g_iCampCount[iClient] == g_iCampTime)
        for(
int i 1<= MaxClientsi++)
            
//S_PrintToChat(i, "%T", "Camp_Message1", i, iClient);

    
if(g_iCampCount[iClient] >= g_iCampTime)
    {
        
float fVec[3];
        
GetClientAbsOrigin(iClientfVec);
        
fVec[2] += 10;

        
//TE_SetupBeamRingPoint(fVec, 10.0, 375.0, g_iBeamSprite, g_iHaloSprite, 0, 10, 0.6, 10.0, 0.5, GetClientTeam(iClient) == 3 ? {0, 0, 150, 255} : {150, 0, 0, 255}, 10, 0);
        //TE_SendToAll();

        //EmitAmbientSound("buttons/blip1.wav", fVec, iClient, SNDLEVEL_RAIDSIREN);

        
SlapPlayer(iClientg_iSlapDamagetrue);
    }

    return 
Plugin_Continue;
}

bool IsCamping(int iClient)
{
    
float fCurrentPos[3];
    
GetClientAbsOrigin(iClientfCurrentPos);

    if(
g_fRadius GetVectorDistance(g_fSpawnEyeAng[iClient], fCurrentPos)) return false;

    if(
g_fRadius GetVectorDistance(g_fLastPos[iClient], fCurrentPos)) return true;

    
g_fLastPos[iClient] = fCurrentPos;
    return 
false;
}

void DeleteTimer(int iClient)
{
    if(
g_hTimerChecker[iClient] != null)
    {
        
KillTimer(g_hTimerChecker[iClient]);
        
g_hTimerChecker[iClient] = null;
    }
}

// bool IsWarmup()
// {
    // return (GameRules_GetProp("m_bWarmupPeriod") == 1);
// } 

Last edited by hl2dmgamer; 12-12-2023 at 23:10. Reason: Solved
hl2dmgamer is offline
101
Member
Join Date: Nov 2023
Old 12-12-2023 , 05:05   Re: Hi, is it possible to change this code from a kill function to a respawn function
Reply With Quote #2

I have to suppose that is cstrike , try this for test :

PHP Code:
#include <cstrike>

#define g_iCampTime        12
#define g_fRadius        130.0

float g_fLastPos[MAXPLAYERS 1][3];
float g_fSpawnEyeAng[MAXPLAYERS 1][3];

Handle g_hTimerChecker[MAXPLAYERS 1];

int g_iCampCount[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
HookEvent("round_end"Event_RoundEndEventHookMode_Pre);
    
HookEvent("player_spawn"Event_PlayerSpawnEventHookMode_Post);
    
HookEvent("player_death"Event_PlayerDeath);
}

public 
void OnClientDisconnect(int P)
{
    
delete_timer(P);
}

public 
Action Event_RoundEnd(Event hEventchar[] sEvNamebool bDontBroadcast)
{
    for(
int i 1<= MaxClientsi++)
    {
        
delete_timer(i);
    }
    return 
Plugin_Continue;
}

public 
Action Event_PlayerDeath(Event hEventchar[] sEvNamebool bDontBroadcast)
{
    
delete_timer(GetClientOfUserId(hEvent.GetInt("userid")));
    return 
Plugin_Continue;
}

public 
Action Event_PlayerSpawn(Event hEventchar[] sEvNamebool bDontBroadcast)
{
    
int P GetClientOfUserId(hEvent.GetInt("userid"));
    if (
IsFakeClient(P))
    {
        
GetClientAbsOrigin(Pg_fLastPos[P]);
        
GetClientAbsOrigin(Pg_fSpawnEyeAng[P]);
        
g_iCampCount[P]=0;
        if (
g_hTimerChecker[P]==INVALID_HANDLE)
        
g_hTimerChecker[P] = CreateTimer(2.0,Timer_Checker,P,TIMER_REPEAT);
    }
    return 
Plugin_Continue;
}

public 
Action Timer_Checker(Handle hTimerany P)
{
    if(
IsCamping(P)) g_iCampCount[P] += 2;
    else 
g_iCampCount[P] = 0;

    if(
g_iCampCount[P] >= g_iCampTime)
    {
        
CS_RespawnPlayer(P);
    }
    return 
Plugin_Continue;
}

bool IsCamping(int P)
{
    
float fCurrentPos[3];
    
GetClientAbsOrigin(PfCurrentPos);

    if(
g_fRadius GetVectorDistance(g_fSpawnEyeAng[P], fCurrentPos)) return false;

    if(
g_fRadius GetVectorDistance(g_fLastPos[P], fCurrentPos)) return true;

    
g_fLastPos[P] = fCurrentPos;
    return 
false;
}

delete_timer(int P)
{
    if(
g_hTimerChecker[P] != INVALID_HANDLE)
        
delete g_hTimerChecker[P];

Attached Files
File Type: sp Get Plugin or Get Source ([CS]Respawn_Camping_Bots.sp - 28 views - 2.0 KB)

Last edited by 101; 12-13-2023 at 02:32. Reason: #include <sourcemod> is not necessary
101 is offline
hl2dmgamer
Junior Member
Join Date: Dec 2023
Old 12-12-2023 , 16:25   Re: Hi, is it possible to change this code from a kill function to a respawn function
Reply With Quote #3

Thanks friend
small and simple plugin found where?
Test passed, you're right, it's not intended for hl2dm.
I did an experiment and
rewrote "CS_RespawnPlayer(P);" to "DispatchSpawn(P);"
added "#include <sdktools> #include <halflife>"
Clean compile without warnings
wow and it works ))

Bots on vast maps and complex structures will remain stationary. Respawn fixed it.

Quote:
Originally Posted by 101 View Post
I have to suppose that is cstrike , try this for test :

PHP Code:
#include <sourcemod>
#include <cstrike>

#define g_iCampTime        12
#define g_fRadius        130.0

float g_fLastPos[MAXPLAYERS 1][3];
float g_fSpawnEyeAng[MAXPLAYERS 1][3];

Handle g_hTimerChecker[MAXPLAYERS 1];

int g_iCampCount[MAXPLAYERS 1];

public 
void OnPluginStart()
{
    
HookEvent("round_end"Event_RoundEndEventHookMode_Pre);
    
HookEvent("player_spawn"Event_PlayerSpawnEventHookMode_Post);
    
HookEvent("player_death"Event_PlayerDeath);
}

public 
void OnClientDisconnect(int P)
{
    
delete_timer(P);
}

public 
Action Event_RoundEnd(Event hEventchar[] sEvNamebool bDontBroadcast)
{
    for(
int i 1<= MaxClientsi++)
    {
        
delete_timer(i);
    }
    return 
Plugin_Continue;
}

public 
Action Event_PlayerDeath(Event hEventchar[] sEvNamebool bDontBroadcast)
{
    
delete_timer(GetClientOfUserId(hEvent.GetInt("userid")));
    return 
Plugin_Continue;
}

public 
Action Event_PlayerSpawn(Event hEventchar[] sEvNamebool bDontBroadcast)
{
    
int P GetClientOfUserId(hEvent.GetInt("userid"));
    if (
IsFakeClient(P))
    {
        
GetClientAbsOrigin(Pg_fLastPos[P]);
        
GetClientAbsOrigin(Pg_fSpawnEyeAng[P]);
        
g_iCampCount[P]=0;
        if (
g_hTimerChecker[P]==INVALID_HANDLE)
        
g_hTimerChecker[P] = CreateTimer(2.0,Timer_Checker,P,TIMER_REPEAT);
    }
    return 
Plugin_Continue;
}

public 
Action Timer_Checker(Handle hTimerany P)
{
    if(
IsCamping(P)) g_iCampCount[P] += 2;
    else 
g_iCampCount[P] = 0;

    if(
g_iCampCount[P] >= g_iCampTime)
    {
        
CS_RespawnPlayer(P);
    }
    return 
Plugin_Continue;
}

bool IsCamping(int P)
{
    
float fCurrentPos[3];
    
GetClientAbsOrigin(PfCurrentPos);

    if(
g_fRadius GetVectorDistance(g_fSpawnEyeAng[P], fCurrentPos)) return false;

    if(
g_fRadius GetVectorDistance(g_fLastPos[P], fCurrentPos)) return true;

    
g_fLastPos[P] = fCurrentPos;
    return 
false;
}

delete_timer(int P)
{
    if(
g_hTimerChecker[P] != INVALID_HANDLE)
        
delete g_hTimerChecker[P];


Last edited by hl2dmgamer; 12-12-2023 at 23:12.
hl2dmgamer is offline
101
Member
Join Date: Nov 2023
Old 12-13-2023 , 01:16   Re: Hi, is it possible to change this code from a kill function to a respawn function
Reply With Quote #4

Look at this :DispatchSpawn
You can see the required *.inc for this function on the top of the page . Which is sdktools_functions.inc
Thus, ur *.sp file should start only with one single line :
PHP Code:
#include <sdktools_functions> 

Regrads
Attached Files
File Type: sp Get Plugin or Get Source ([HL2DM]Respawn_Camping_Bots.sp - 28 views - 2.0 KB)

Last edited by 101; 12-13-2023 at 04:37.
101 is offline
hl2dmgamer
Junior Member
Join Date: Dec 2023
Old 12-13-2023 , 16:17   Re: Hi, is it possible to change this code from a kill function to a respawn function
Reply With Quote #5

Quote:
Originally Posted by 101 View Post
Look at this :DispatchSpawn
You can see the required *.inc for this function on the top of the page . Which is sdktools_functions.inc
Thus, ur *.sp file should start only with one single line :
PHP Code:
#include <sdktools_functions> 

Regrads
Hello Friend
Thank you
He was glad to learn from them,
also only "#include <sdktools_functions> " is used - good
change "if (IsFakeClient(P)) " to "if (IsPlayerAlive(P))" respawn for all camping players
cheers

how even a small change makes big things

Last edited by hl2dmgamer; 12-13-2023 at 16:26.
hl2dmgamer 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 03:03.


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