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

request to add code to a run/sprint plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Tote
Senior Member
Join Date: Jul 2023
Old 08-24-2023 , 11:44   Re: request to add code to a run/sprint plugin
Reply With Quote #21

Quote:
Originally Posted by Siska1 View Post
Again no work and no run. In my code everything works for me and I wanted to add a simple constraint so I don't waste my runs. There should be no sound when I switch to a weapon and the message should be to every player when he enters the server, and not at the beginning of the map as it is now. if I switch quickly to a knife and then to a weapon, it shouldn't be considered running, for example. And that's why I want to add that it's on the W button, not just by pulling out the knife. I deleted the Sprint plugin you showed me and would never use it again no matter what, so I set out to make my own better one.
I hope you understand me, because I use google for translations. I'll certainly keep trying to get your code into mine, but whether I'll succeed is rather doubtful.
(1): The sound when you switch weapon is not because you are switching the weapons, it's because the sprint works only when Player has knife in hand, so if player changes to any other weapon when last weapon was knife so it will execute the sprint end sound.
(2): The message is not at the beginning of the map, It shows every 20 seconds as you set in the cvar.
(3): I edited your plugin and made it to show message when player has joined to the server.
(4): there was not even need to put Fourth jump or some other to count the sprints, I've added the limit, You can change sprint limits by changing cvar "sprint_limit"

PHP Code:
#include <amxmodx>
#include <fun>
#include <hamsandwich>

#define PLUGIN_VERSION "1.0.1"
new g_pSpeed
new g_pSprintDuration
new delaymsgtime
//limit
new g_Limit[33]; // used to count limits
new g_pSprintLimit// used to check limits

// 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_VERSIONFCVAR_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");
    
g_pSprintLimit register_cvar("sprint_limit""3");
        
delaymsgtime register_cvar("cmessage_delay""10.0");
}

public 
client_putinserver(id)
{
        
set_task(get_pcvar_float(delaymsgtime), "ShowSprintMessage"id)
}
public 
fwHamPlayerSpawnPost(id)
{
    
g_Limit[id] = 0;
}

public 
OnSelectKnife(id)
{
    if (
is_user_alive(id))
    {
        if (
g_Limit[id] >= get_pcvar_num(g_pSprintLimit)) // checking if player has reached maximum sprint numbers (which is in cvar sprint_limit)
        
{
            return 
PLUGIN_HANDLED// means the player has reached maximum limit of sprints!
        
}
        else
        {
            
set_user_maxspeed(idget_user_maxspeed(id) + get_pcvar_float(g_pSpeed));
            
set_task(get_pcvar_float(g_pSprintDuration), "EndFastKnife"id);
            
g_Limit[id]++; // counting +1 for player limit
        
}
    }
    return 
PLUGIN_HANDLED;
}

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

public 
ShowSprintMessage(id)
{
    
client_print(idprint_chat"You can sprint with a knife in hand for %d seconds!"get_pcvar_num(g_pSprintDuration))
}

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


Last edited by Tote; 08-24-2023 at 11:44.
Tote is offline
Siska1
Senior Member
Join Date: Feb 2020
Location: BedRock
Old 09-28-2023 , 07:20   Re: request to add code to a run/sprint plugin
Reply With Quote #22

this is where I got to :

Code:
#include <amxmodx>
#include <fun>
#include <engine>
#include <hamsandwich>
#include <cromchat>

#define PLUGIN_VERSION "1.0.1"
#define SPRINT_END_SOUND "misc/breathe2.wav"
#define SPRINT_MESSAGE_INTERVAL 300.0
#define FAST_KNIFE_DELAY 20.0

#define SPRINT_MESSAGE_FORMAT "&x03%s&x01, you can &x04sprint &x01with a knife in hand &x04%d &x01times for &x04%0.1f &x01seconds. Next &x04sprint &x01every &x04%.1f &x01seconds."

new g_pSpeed[3];
new g_Limit[33];
new g_sprint[33];
new g_LastSprint[33];
new Float:g_LastJoinTime[33];
new Float:g_LastMessageTime[33];
new g_MaxSprints;
new g_ReachedMaxSprint[33];

public plugin_init()
{
    register_plugin("Fast Knife", PLUGIN_VERSION, "OciXCrom, tes-onez crew");
    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[0] = register_cvar("fastknife_speed", "150.0");
    g_pSpeed[1] = register_cvar("sprint_duration", "2.0");
    g_pSpeed[2] = register_cvar("sprint_coundown", "10.0");
    g_MaxSprints = register_cvar("max_sprints", "3");
}

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

public fwHamPlayerSpawnPost(id)
{
    g_Limit[id] = 0;
    g_LastSprint[id] = false;
    g_sprint[id] = true;
    g_LastJoinTime[id] = get_gametime();
    g_ReachedMaxSprint[id] = false;

    set_task(FAST_KNIFE_DELAY, "ShowSprintMessage", id);
}

public OnSelectKnife(id)
{
    if (is_user_alive(id) && get_user_button(id) && IN_FORWARD && get_user_oldbutton(id) && IN_FORWARD)
    {
        if(g_sprint[id])
        {
            if(g_Limit[id] >= get_pcvar_num(g_MaxSprints))
            {
                if (!g_ReachedMaxSprint[id])
                {
                    new szName[33];
                    get_user_name(id, szName, charsmax(szName));
		    
                    CC_SendMatched(id, CC_COLOR_TEAM, "&x03%s&x01, you've reached the maximum &x04sprint &x01limit. Again on next spawn !!!", szName);
                    g_ReachedMaxSprint[id] = true;
                }
                return PLUGIN_HANDLED;
            }
            g_sprint[id] = false;
            set_user_maxspeed(id, get_user_maxspeed(id) + get_pcvar_float(g_pSpeed[0]));
            set_task(get_pcvar_float(g_pSpeed[1]), "EndFastKnife", id);
            g_Limit[id]++;
        }
    }
    return PLUGIN_HANDLED;
}

public RefreshFastKnife(id)
{
    if(is_user_connected(id) && !g_sprint[id])
    {
        g_sprint[id] = true;
    }
}

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);
        set_task(get_pcvar_float(g_pSpeed[2]), "RefreshFastKnife", id);
    }
}

public ShowSprintMessage(id) {
    if (!g_LastMessageTime[id] || get_gametime() - g_LastMessageTime[id] >= SPRINT_MESSAGE_INTERVAL) {
        new playerName[32];
        get_user_name(id, playerName, sizeof(playerName));
        CC_SendMatched(id, CC_COLOR_TEAM, SPRINT_MESSAGE_FORMAT, playerName, get_pcvar_num(g_MaxSprints), get_pcvar_float(g_pSpeed[1]), get_pcvar_float(g_pSpeed[2]));
        g_LastMessageTime[id] = get_gametime();
    }
}
__________________

Last edited by Siska1; 10-01-2023 at 09:15.
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 14:42.


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