Raised This Month: $32 Target: $400
 8% 

Longjump command [Need Help]


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-25-2015 , 17:57   Longjump command [Need Help]
Reply With Quote #1

The Idea

Having a command called something like "sm_xlongjump (userid) (boost)"
doing this by using "RegServerCmd" so i can "set" 1 specific players longjump from console, without affecting other players jump.


Was messing around with this piece of code (messy as hell), but can't seem to get it working properly.
And yes it compiles.

Note: this is including a height handle, just for testing and should not be in the finish code tho.

Code:
#include <sourcemod>
#include <morecolors>          
#include <sdktools>

new VelocityOffset_0;
new VelocityOffset_1;
new BaseVelocityOffset;

new Handle:data_pack_jump = INVALID_HANDLE;
new Float:BoostFloat[MAXPLAYERS+1];
new Handle:hPush;
new Handle:hHeight;
new bool:g_bPlayerJumped[MAXPLAYERS+1];


public OnPluginStart()
{
	HookEvent("player_jump",PlayerJumpEvent);
  
	VelocityOffset_0=FindSendPropOffs("CBasePlayer","m_vecVelocity[0]");
  
	if(VelocityOffset_0==-1)
		SetFailState("[xlongjump] Error: Failed to find Velocity[0] offset, aborting");
	VelocityOffset_1=FindSendPropOffs("CBasePlayer","m_vecVelocity[1]");
  
	if(VelocityOffset_1==-1)
		SetFailState("[xlongjump] Error: Failed to find Velocity[1] offset, aborting");
	BaseVelocityOffset=FindSendPropOffs("CBasePlayer","m_vecBaseVelocity");
  
	if(BaseVelocityOffset==-1)
		SetFailState("[xlongjump] Error: Failed to find the BaseVelocity offset, aborting");

	hPush=CreateConVar("xlongjump_push","1.0","The forward push when you jump");
	hHeight=CreateConVar("xlongjump_height","1.0","The upward push when you jump");

	AutoExecConfig();

	RegServerCmd("sm_xlongjump", JumpRegister);
}

public Action:JumpRegister(args)
{
		new args_ = GetCmdArgs();
		if (args_ < 2||args_ > 2)
		{
			PrintToServer("Error: sm_xlongjump <userid> <boostamount>");
			return Plugin_Handled;
		}
		new String:userid[128];
		new String:boost[128];
		GetCmdArg(1, userid, sizeof(userid));
		GetCmdArg(2, boost, sizeof(boost));
		new i_userid = StringToInt(userid);
		new client = GetClientOfUserId(i_userid);
		Jump_cl(client);

		return Plugin_Continue;
}

public Jump_cl(client)
{
	if( client != 0 && IsClientInGame(client) && IsPlayerAlive(client) ) // victim still in game
	{
		data_pack_jump = CreateDataPack();
		ResetPack(data_pack_jump, true);
		WritePackCell(data_pack_jump, client);
		CPrintToChat(client, "{lightgreen}Longjump activated.");
		Jump_on(data_pack_jump);
	}
}

public Jump_on(Handle:pack)
{
		ResetPack(pack);
		new client = ReadPackCell(pack);
		new Float:boost = ReadPackFloat(pack);
		BoostFloat[client] = boost;
		g_bPlayerJumped[client] = true;
}

public PlayerJumpEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
	for(new i=1;i<=MaxClients;i++)
	{
		if(g_bPlayerJumped[i])
			continue;
		new Float:finalvec[3];
		finalvec[0]=GetEntDataFloat(i,VelocityOffset_0)*GetConVarFloat(hPush)/2.0;
		finalvec[1]=GetEntDataFloat(i,VelocityOffset_1)*GetConVarFloat(hPush)/2.0;
		finalvec[2]=GetConVarFloat(hHeight)*50.0;
		SetEntDataVector(i,BaseVelocityOffset,finalvec,true);
	}
}
xines is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-26-2015 , 07:39   Re: Longjump command [Need Help]
Reply With Quote #2

Forgot to mention this is for [CS:S]
xines is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 06-26-2015 , 09:00   Re: Longjump command [Need Help]
Reply With Quote #3

PHP Code:
#include <sourcemod>
#include <morecolors>          
#include <sdktools>

new Float:Boost[MAXPLAYERS 1] = {0.0, ...}
new 
bool:g_bPlayerHasJump[MAXPLAYERS 1] = {false, ...};

public 
OnPluginStart()
{
    
HookEvent("player_jump"PlayerJumpEvent);

    
RegServerCmd("sm_xlongjump"JumpRegister);
}

public 
Action:JumpRegister(args)
{
    new 
args_ GetCmdArgs();
    if (
args_ != 2)
    {
        
PrintToServer("Error: sm_xlongjump <userid> <boostamount>");
        return 
Plugin_Handled;
    }
    
    new 
String:userid[32], String:boost[32];
    
    
GetCmdArg(1useridsizeof(userid));
    
GetCmdArg(2boostsizeof(boost));
    new 
client GetClientOfUserId(StringToInt(userid));
    
    
Boost[client] = StringToFloat(boost);
    
g_bPlayerHasJump[client] = true;
    
    
CPrintToChat(client"{lightgreen}Longjump activated.");

    return 
Plugin_Handled;
}

public 
Action:PlayerJumpEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    
    if(!
g_bPlayerHasJump[client])
        return 
Plugin_Continue;
        
    
float v[3], nv[3];
    
GetEntPropVector(clientProp_Data"m_vecBaseVelocity"v);
    
nv v;
    
nv[2] = 0.0;
    
NormalizeVector(vnv);
    
v[0] += nv[0] * Boost[client];
    
v[1] += nv[1] * Boost[client];
    
    
TeleportEntity(clientNULL_VECTORNULL_VECTORv);
    
    return 
Plugin_Continue;

Miu is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-26-2015 , 18:33   Re: Longjump command [Need Help]
Reply With Quote #4

Hey Miu, the code u sent gave me compile error saying that:

Line 45 got a undefined symbol "v"
xines is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 06-26-2015 , 19:25   Re: Longjump command [Need Help]
Reply With Quote #5

change the line to

PHP Code:
new Float:v[3], Float:nv[3]; 
if u have some outdated compiler
Miu is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-26-2015 , 19:37   Re: Longjump command [Need Help]
Reply With Quote #6

Well, that fixed the compile error, but the script does not give me longjump when activated

i tried doing the normal "rcon sm_xlongjump 2 3"

console: "Longjump activated."

I jump forward, but nothing happens, still normal?

- I appreciate your help btw
xines is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 06-26-2015 , 20:01   Re: Longjump command [Need Help]
Reply With Quote #7

apparently it needs to be delayed

PHP Code:
#include <sourcemod>
#include <morecolors>          
#include <sdktools>

new Float:Boost[MAXPLAYERS 1] = {0.0, ...}
new 
bool:g_bPlayerHasJump[MAXPLAYERS 1] = {false, ...};

public 
OnPluginStart()
{
    
HookEvent("player_jump"PlayerJumpEvent);

    
RegServerCmd("sm_xlongjump"JumpRegister);
}

public 
Action:JumpRegister(args)
{
    new 
args_ GetCmdArgs();
    if (
args_ != 2)
    {
        
PrintToServer("Error: sm_xlongjump <userid> <boostamount>");
        return 
Plugin_Handled;
    }
    
    new 
String:userid[32], String:boost[32];
    
    
GetCmdArg(1useridsizeof(userid));
    
GetCmdArg(2boostsizeof(boost));
    new 
client GetClientOfUserId(StringToInt(userid));
    
    
Boost[client] = StringToFloat(boost);
    
g_bPlayerHasJump[client] = true;
    
    
CPrintToChat(client"{lightgreen}Longjump activated.");

    return 
Plugin_Handled;
}

public 
addvel(any:client)
{
    new 
Float:v[3], Float:nv[3];
    
GetEntPropVector(clientProp_Data"m_vecVelocity"v);
    
    
nv v;
    
nv[2] = 0.0;
    
NormalizeVector(vnv);
    
v[0] += nv[0] * Boost[client];
    
v[1] += nv[1] * Boost[client];
    
    
TeleportEntity(clientNULL_VECTORNULL_VECTORv);
}

public 
Action:PlayerJumpEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    
    if(!
g_bPlayerHasJump[client])
        return 
Plugin_Continue;
        
    
RequestFrame(addvelclient);
    
    return 
Plugin_Continue;

works with sth like sm_xlongjump 2 500
Miu is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-26-2015 , 20:14   Re: Longjump command [Need Help]
Reply With Quote #8

Seems to be working now thank you so much!

- Any chance to add a "kill longjump" on death so i'll have to give command again on spawn?
Also if possible make boost values like 100 = 1.0 and so on?
xines is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 06-27-2015 , 10:48   Re: Longjump command [Need Help]
Reply With Quote #9

u can hook player_death for the first one, and add w/e arithmetic in the addvel function for the second
Miu is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-27-2015 , 10:56   Re: Longjump command [Need Help]
Reply With Quote #10

I allrdy fixed the values(kinda) in the addvel function by adding *400 to the boost like this for both "Boost[client]*400.0;" seems to work fine, and 1.0 value now gives the correct boost i was looking for

Now i'm playing with the player_death and round_end hook, but i can't seem to find a solution i tried things like this:

PHP Code:
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    if(!
g_bPlayerHasJump[client])
        return 
Plugin_Continue;

    
g_bPlayerHasJump[client] = false;

    return 
Plugin_Continue;

but it just keeps having longjump activated.

Last edited by xines; 06-27-2015 at 10:57. Reason: forgot some text...
xines 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 15:41.


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