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

request to add code to a run/sprint plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Siska1
Senior Member
Join Date: Feb 2020
Location: BedRock
Old 08-18-2023 , 10:18   request to add code to a run/sprint plugin
Reply With Quote #1

Hello people
Can someone help me here to add a running limit so that it can only be run three times in one reincarnation and for example there is a 30 second break between the three runs?
Code:
#include <amxmodx>
#include <fun>

#define PLUGIN_VERSION "1.0.1"
new g_pSpeed
new g_pSprintDuration

public plugin_init()
{
    register_plugin("Fast Knife", PLUGIN_VERSION, "OciXCrom")
    register_cvar("CRXFastKnife", PLUGIN_VERSION, FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED)
    register_event("CurWeapon", "OnSelectKnife", "be", "1=1", "2=29")
    
    g_pSpeed = register_cvar("fastknife_speed", "150.0");
    g_pSprintDuration = register_cvar("sprint_duration", "2.5");
    
    set_task(20.0, "ShowSprintMessage", 0); // Показваме съобщение след X секунди.
}

public OnSelectKnife(id)
{
    if (is_user_alive(id))
    {
        set_user_maxspeed(id, get_user_maxspeed(id) + get_pcvar_float(g_pSpeed));
        set_task(get_pcvar_float(g_pSprintDuration), "EndFastKnife", id); // Активираме таймер за деактивиране след X секунди.
    }
}

public EndFastKnife(id)
{
    if (is_user_alive(id))
    {
        set_user_maxspeed(id, 250.0); // Връщаме нормалната скорост.
    }
}

public ShowSprintMessage(id)
{
    client_print(id, print_chat, "You can sprint with a knife in hand for 2.5 seconds!");
}
__________________
Siska1 is offline
Send a message via Skype™ to Siska1
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 08-18-2023 , 11:13   Re: request to add code to a run/sprint plugin
Reply With Quote #2

hi I imagine that the limit would be individually per player, not global for all
__________________
mlibre is offline
Tote
Senior Member
Join Date: Jul 2023
Old 08-19-2023 , 05:19   Re: request to add code to a run/sprint plugin
Reply With Quote #3

Here you go

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

#define PLUGIN_VERSION "1.0.1"
new g_pSpeed
new g_pSprintDuration
new g_Limit[33];

public plugin_init()
{
register_plugin("Fast Knife", PLUGIN_VERSION, "OciXCrom")
register_cvar("CRXFastKnife", PLUGIN_VERSION, FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED)
register_event("CurWeapon", "OnSelectKnife", "be", "1=1", "2=29")
RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1)

g_pSpeed = register_cvar("fastknife_speed", "150.0");
g_pSprintDuration = register_cvar("sprint_duration", "2.5");

set_task(20.0, "ShowSprintMessage", 0); // ????????? ????????? ???? X ???????.
}

public fwHamPlayerSpawnPost(id)
{
g_Limit[id] = 0
}

public OnSelectKnife(id)
{
if (is_user_alive(id))
{
if(g_Limit[id] >= 3)
{
client_print(id, print_chat, "Sorry, You've reached maximum sprint limit")
return PLUGIN_HANDLED;
}
else
{
set_user_maxspeed(id, get_user_maxspeed(id) + get_pcvar_float(g_pSpeed));
set_task(get_pcvar_float(g_pSprintDuration), "EndFastKnife", id); // ?????????? ?????? ?? ???????????? ???? X ???????.
g_Limit[id]++
}
}
return PLUGIN_HANDLED;
}

public EndFastKnife(id)
{
if (is_user_alive(id))
{
set_user_maxspeed(id, 250.0); // ??????? ?????????? ???????.
}
}

public ShowSprintMessage(id)
{
client_print(id, print_chat, "You can sprint with a knife in hand for 2.5 seconds!");
}
Tote is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 08-19-2023 , 16:20   Re: request to add code to a run/sprint plugin
Reply With Quote #4

@Tote and the 30 seconds where you leave them. in case it is run in csdm mode, the limit will not take effect by hooking Ham_Spawn
__________________
mlibre is offline
Tote
Senior Member
Join Date: Jul 2023
Old 08-20-2023 , 03:34   Re: request to add code to a run/sprint plugin
Reply With Quote #5

Okay, here

#include <amxmodx>
#include <fun>
#include <csdm>

#define PLUGIN_VERSION "1.0.1"
new g_pSpeed
new g_pSprintDuration
new g_Limit[33];
new g_cooldown;
new bool:g_coolingdown[33];

public plugin_init()
{
register_plugin("Fast Knife", PLUGIN_VERSION, "OciXCrom")
register_cvar("CRXFastKnife", PLUGIN_VERSION, FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED)
register_event("CurWeapon", "OnSelectKnife", "be", "1=1", "2=29")

g_pSpeed = register_cvar("fastknife_speed", "150.0");
g_pSprintDuration = register_cvar("sprint_duration", "2.5");
g_cooldown = register_cvar("sprint_cooldown", "30.0");

set_task(20.0, "ShowSprintMessage", 0); // ????????? ????????? ???? X ???????.
}

public OnSelectKnife(id)
{
if (is_user_alive(id))
{
if(g_Limit[id] >= 3)
{
client_print(id, print_chat, "Sorry, You've reached maximum sprint limit")
return PLUGIN_HANDLED;
}
else if(g_coolingdown[id] == true)
{
client_print(id, print_chat, "You must wait 30 seconds to sprint again!")
return PLUGIN_HANDLED
}
else
{
set_user_maxspeed(id, get_user_maxspeed(id) + get_pcvar_float(g_pSpeed));
set_task(get_pcvar_float(g_pSprintDuration), "EndFastKnife", id); // ?????????? ?????? ?? ???????????? ???? X ???????.
g_coolingdown[id] = true
set_task(get_pcvar_float(g_cooldown), "cooldown", id)
g_Limit[id]++
}
}
return PLUGIN_HANDLED;
}
public client_putinserver(id)
{
g_coolingdown[id] = false
g_Limit[id] = 0
}
public cooldown(id)
{
g_coolingdown[id] = false
}

public EndFastKnife(id)
{
if (is_user_alive(id))
{
set_user_maxspeed(id, 250.0); // ??????? ?????????? ???????.
}
}

public ShowSprintMessage(id)
{
client_print(id, print_chat, "You can sprint with a knife in hand for 2.5 seconds!");
}


public csdm_PostSpawn(id)
{
g_Limit[id] = 0
g_coolingdown[id] = false // put // in start of this line if you dont want to reset cooldown on spawn
}

Last edited by Tote; 08-20-2023 at 03:36.
Tote is offline
Siska1
Senior Member
Join Date: Feb 2020
Location: BedRock
Old 08-21-2023 , 07:49   Re: request to add code to a run/sprint plugin
Reply With Quote #6

Tote, thanks a lot for the first option. I got this far and now I'm struggling to add more stuff. The second option with csdm doesn't work for me. I couldn't handle the 30 second option. Now I'll try to make the execution start when W is pressed, not when the knife is out or with +USE maybe.
Code:
#include <amxmodx>
#include <fun>
#include <hamsandwich>

#define PLUGIN_VERSION "1.0.1"
new g_pSpeed
new g_pSprintDuration
new g_Limit[33];
new g_Jumps[33];
new g_FourthJump[33];

// Add a new sound constant for the sprint end sound
#define SPRINT_END_SOUND "sound/breathe2.wav"

public plugin_init()
{
    register_plugin("Fast Knife", PLUGIN_VERSION, "OciXCrom")
    register_cvar("CRXFastKnife", PLUGIN_VERSION, FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED)
    register_event("CurWeapon", "OnSelectKnife", "be", "1=1", "2=29")
    RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1)

    g_pSpeed = register_cvar("fastknife_speed", "150.0");
    g_pSprintDuration = register_cvar("sprint_duration", "2.0");

    set_task(20.0, "ShowSprintMessage", 0);
}

public fwHamPlayerSpawnPost(id)
{
    g_Limit[id] = 0;
    g_Jumps[id] = 0;
    g_FourthJump[id] = false;
}

public OnSelectKnife(id)
{
    if (is_user_alive(id))
    {
        if (g_Limit[id] >= 3)
        {
            if (g_FourthJump[id])
            {
                return PLUGIN_HANDLED;
            }
            else
            {
                client_print(id, print_chat, "Sorry, You've reached maximum sprint limit");
                g_FourthJump[id] = true;
                return PLUGIN_HANDLED;
            }
        }
        else
        {
            set_user_maxspeed(id, get_user_maxspeed(id) + get_pcvar_float(g_pSpeed));
            set_task(get_pcvar_float(g_pSprintDuration), "EndFastKnife", id);
            g_Limit[id]++;
            g_Jumps[id]++;
        }
    }
    return PLUGIN_HANDLED;
}

public EndFastKnife(id)
{
    if (is_user_alive(id))
    {
        set_user_maxspeed(id, 250.0);
        // Play the sprint end sound
        client_cmd(id, "spk %s", SPRINT_END_SOUND);
    }
}

public ShowSprintMessage(id)
{
    new Float:sprintDuration = get_pcvar_float(g_pSprintDuration);
    new msg[128];
    formatex(msg, sizeof(msg), "You can sprint with a knife in hand for %0.1f seconds!", sprintDuration);
    client_print(id, print_chat, msg);
}

public plugin_precache()
{
    // Precache the sprint end sound
    precache_sound(SPRINT_END_SOUND);
}
__________________

Last edited by Siska1; 08-21-2023 at 11:43.
Siska1 is offline
Send a message via Skype™ to Siska1
Tote
Senior Member
Join Date: Jul 2023
Old 08-21-2023 , 11:51   Re: request to add code to a run/sprint plugin
Reply With Quote #7

What do you mean by you couldn't handle the 30 seconds? i added a cvar so you can change the 30 seconds time as you want. As for the sprint to be on W button if pressed:

button = pev(id, pev_button);
oldbuttons = pev(id, pev_oldbuttons);
Only when W is pressed:
if(button & IN_FORWARD)
Only when W is pressed 2 times:
if(button & IN_FORWARD && !(oldbuttons & IN_FORWARD))

As for "E" button:
if(button & IN_USE)
can do same like above for 2 time by pressing "E" button

EDIT: regarding second option, means you're not using csdm mod, you're just using some plugins or different csdm mod (private or something) i made it to match only with bailopan's csdm mod, you can replace RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1) if it works for you, then i guess wont be problem anymore.

Last edited by Tote; 08-21-2023 at 12:20.
Tote is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 08-21-2023 , 12:40   Re: request to add code to a run/sprint plugin
Reply With Quote #8

this plugin applies only for the knife, do you want to keep it that way or for all weapons
__________________
mlibre is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 08-21-2023 , 13:16   Re: request to add code to a run/sprint plugin
Reply With Quote #9

Quote:
Originally Posted by Siska1 View Post
Can someone help me here to add a running limit so that it can only be run three times in one reincarnation and for example there is a 30 second break between the three runs?
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fun>
#include <engine>

#define PLUGIN "Fast Knife"
#define VERSION "1.7"
#define AUTHOR "OciXCrom & mlibre"

#if !defined MAX_PLAYERS
const MAX_PLAYERS 32
#endif

new g_pActive
new g_pLimit
new g_pSpeed
new g_pSprintDuration
new g_pShowSprintMessage
new g_pRespawn
new g_pSound

enum _
:
{
    
fspawn,
    
run,
    
limit,
    
delay
}

new 
iPlayer[MAX_PLAYERS 1][x]

const 
TASK_ID 59141

// Add a new sound constant for the sprint end sound
new const SPRINT_END_SOUND[] = "fvox/fuzz.wav"

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_cvar("CRXFastKnife"VERSIONFCVAR_SERVER FCVAR_SPONLY FCVAR_UNLOGGED)
    
    
register_event("CurWeapon""OnSelectKnife""be""1=1""2=29")
    
    
g_pActive register_cvar("fastknife_active""1")
    
g_pLimit register_cvar("fastknife_limit""3")
    
g_pSpeed register_cvar("fastknife_speed""150.0")
    
g_pSprintDuration register_cvar("sprint_duration""30")
    
g_pShowSprintMessage register_cvar("fastknife_msg""1")
    
g_pRespawn register_cvar("fastknife_respawn""1")
    
g_pSound register_cvar("fastknife_sound""1")
    
    
RegisterHam(Ham_Player_ImpulseCommands"player""Ham_Player_ImpulseCmds")
    
RegisterHam(Ham_Spawn"player""Ham_SpawnPlayer_Post"1)
    
RegisterHam(Ham_Killed"player""Ham_KilledPlayer_Post"1)
}

public 
plugin_precache()
{
    
// Precache the sprint end sound
    
precache_sound(SPRINT_END_SOUND)
}

public 
set_fastknife(id)
{
    if( !
get_pcvar_num(g_pActive) )
    {
        
client_print(idprint_chat"%s: is disabled"PLUGIN)
        
        return
    }
    
    if(
iPlayer[id][limit] >= get_pcvar_num(g_pLimit))
    {
        
client_print(idprint_chat"%s: you have reached your usage limit. %d maximum allowed."PLUGINiPlayer[id][limit])
        
        return
    }
    
    static 
iTimestampiTimestamp get_systime()
    
    if(
iPlayer[id][delay] > iTimestamp)
    {
        if(
iPlayer[id][run])
        {
            
client_print(idprint_chat"%s: you have %d seconds left"PLUGINiPlayer[id][delay] - iTimestamp)
        }
        else
        {
            
client_print(idprint_chat"%s: wait %d seconds for your next use!"PLUGINiPlayer[id][delay] - iTimestamp)
        }
        
        return
    }
    
    if( !
is_user_alive(id) )
    {
        
client_print(idprint_chat"%s: you have to be alive to use this."PLUGIN)
        
        return
    }
    
    
iPlayer[id][run] = 1
    
    iPlayer
[id][limit]++
    
    
set_task(float(get_pcvar_num(g_pSprintDuration)), "EndFastKnife"id TASK_ID)
        
    
iPlayer[id][delay] = iTimestamp get_pcvar_num(g_pSprintDuration)
    
    
client_print(idprint_chat"%s: is running! %d seconds remaining, used (%d of %d)"PLUGINiPlayer[id][delay] - iTimestampiPlayer[id][limit], get_pcvar_num(g_pLimit))
}
    
public 
OnSelectKnife(id)
{
    if(
iPlayer[id][run] && iPlayer[id][limit])
    {
        
set_user_maxspeed(idget_user_maxspeed(id) + get_pcvar_float(g_pSpeed))
    }
}

public 
EndFastKnife(id)
{
    
id -= TASK_ID
    
    iPlayer
[id][run] = 0
    
    
if(is_user_alive(id))
    {
        
reset_speed(id)
    }
    
    if(
iPlayer[id][limit] < get_pcvar_num(g_pLimit))
    {
        
iPlayer[id][delay] = get_systime() + get_pcvar_num(g_pSprintDuration)
    }
    
    if(
get_pcvar_num(g_pSound))
    {
        
client_cmd(id"spk %s"SPRINT_END_SOUND)
    }
    
    
client_print(idprint_chat"%s: your fun is over! times used (%d of %d)"PLUGINiPlayer[id][limit], get_pcvar_num(g_pLimit))
}

public 
Ham_Player_ImpulseCmds(id)
{
    if(
entity_get_int(idEV_INT_impulse) == 201)    //<-key=T
    
{
        
set_fastknife(id)
    }
}

public 
Ham_SpawnPlayer_Post(id)
{
    if(
iPlayer[id][fspawn] || !is_user_alive(id))
        return 
HAM_IGNORED
    
    
if(get_pcvar_num(g_pActive) && get_pcvar_num(g_pShowSprintMessage))
    {
        
iPlayer[id][fspawn] = 1
        
        client_print
(idprint_chat"%s: you can sprint with a knife in hand for %d seconds!"PLUGINget_pcvar_num(g_pSprintDuration))
        
client_print(idprint_chat"%s: activate it with the key ^"T^""PLUGIN)
    }
    
    return 
HAM_IGNORED
}

public 
Ham_KilledPlayer_Post(id)
{
    if(
iPlayer[id][run] && get_pcvar_num(g_pRespawn))
    {
        
iPlayer[id][run] = 0
        
        remove_task
(id TASK_ID)
        
        
reset_speed(id)
        
        
client_print(idprint_chat"%s: you have lost this ability!"PLUGIN)
    }
}

stock reset_speed(id)
{
    
set_user_maxspeed(id250.0)

__________________

Last edited by mlibre; 08-23-2023 at 14:57. Reason: upd 1.7
mlibre is offline
Siska1
Senior Member
Join Date: Feb 2020
Location: BedRock
Old 08-22-2023 , 07:00   Re: request to add code to a run/sprint plugin
Reply With Quote #10

First I want to thank you both for your help. I can't write these things without help. I wanted to tell you that I don't use csdm. I also wanted to tell you exactly how I'm trying to get it to work. In principle, it does not necessarily have to be with a command in the chat. It should be with a button and when the button is pressed, then the run should work. I couldn't handle the 30 second option and couldn't write it in my code, so I removed it. And I said I'm going to try to see how you do that option and I'm going to try to get it into the code. My message at the beginning of the map should be such that every time someone enters the server, it says that there is a run after certain seconds. Now I remembered that as it is now, people will not be able to see that message, for example, if they enter the middle of the map. I've given you my code so you can see how far I'm getting and where I'm going wrong.

The mlibre plugin is very well designed, but it should be on a button and not with a chat command or after the chat command it should work with a button. Also, for some reason out of 3 runs only one worked and only for a second.
__________________

Last edited by Siska1; 08-22-2023 at 07:04.
Siska1 is offline
Send a message via Skype™ to Siska1
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 13:55.


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