Raised This Month: $47 Target: $400
 11% 

Help on code pls


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bally
Senior Member
Join Date: Aug 2015
Old 09-15-2015 , 14:42   Help on code pls
Reply With Quote #1

line 161-170 I have no clue why it's returning me a false value instead of a true value ( I tried with bots! ) // FIXED
However I'm also having a problem with DataPacks, any clue on how to fix it? ( last function )

Code:
L 09/15/2015 - 22:31:55: [SM] Native "ReadPackCell" reported: DataPack operation is out of bounds.

Thanks and good luck.
Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "Grandpa -a"
#define PLUGIN_VERSION "1.14"

#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <sdkhooks>
#include <smlib>

new bool:DisableSwitch[MAXPLAYERS + 1];
new g_iWeapon[MAXPLAYERS + 1]; // STORES EACH CLIENT'S WEP.

public Plugin myinfo = 
{
	name = "takeweapon", 
	author = PLUGIN_AUTHOR, 
	description = "", 
	version = PLUGIN_VERSION, 
	url = ""
};

public void OnPluginStart()
{
	regcmds();
	if (!IsCSGO())
	{
		SetFailState("CS:GO Only.");
	}
}


public OnClientPutInServer(client)
{
	DisableSwitch[client] = false; // automatically sets false when client joins server.
}

public Action:Command_Switch(client, args)
{
	DisableSwitch[client] = !DisableSwitch[client];
	if (DisableSwitch[client])
	{
		PrintToChat(client, "[\x0ESwitch Weapon\x01] You have \x0Fdisabled\x01 switching!");
	}
	else
	{
		PrintToChat(client, "[\x0ESwitch Weapom\x01] You have \x06enabled\x01 switching!");
	}
	return Plugin_Handled; // after setting, end the plugin.
}

stock bool:IsCSGO()
{
	new String:bufferString[16];
	GetGameFolderName(bufferString, 16);
	if (StrEqual(bufferString, "csgo", false))
	{
		LogMessage("Success!");
		return true;
	}
	else
	{
		LogMessage("Failed to load plugin, CS:GO ony!");
		return false;
	}
}
bool:IsValidClient(client)
{
	if (!(1 <= client <= MaxClients) || !IsClientInGame(client))
		return false;
	
	return true;
}

stock bool:exec_PreTakeWeapon(player1, player2)
{
	if (IsValidClient(player1))
	{
		g_iWeapon[player1] = GetPlayerWeaponSlot(player1, 0);
		if (g_iWeapon[player1] == -1) { return false; }
		
		new String:szClClassID[64];
		GetEdictClassname(g_iWeapon[player2], szClClassID, sizeof(szClClassID));
		
		Client_RemoveWeapon(player1, szClClassID);
		return true;
	}
}

stock regcmds()
{
	RegConsoleCmd("sm_takeweapon", command_takeWeapon, "self-explanatory...");
	RegConsoleCmd("sm_takeweaponoff", Command_Switch, "disables the ability for other people to grab your weapon.");
}

public Action:command_takeWeapon(client, args)
{
	if (args < 1)
	{
		PrintToChat(client, "[\x0ESwitch Weapon\x01] Usage: sm_switchknife <player>");
		return Plugin_Handled;
	}
	new String:arg[32];
	GetCmdArg(1, arg, sizeof(arg)); // get args
	
	new target = FindTarget(client, arg, false, false); // args = player
	
	/** Possible Errors go here**/
	if (target == -1)
	{
		PrintToChat(client, "[\x0ESwitch Weapon\x01] \x07Can't find player!");
		return Plugin_Handled;
	}
	else if (DisableSwitch[target])
	{
		PrintToChat(client, "[\x0ESwitch Weapon\x01] \x07That person has disabled switching!");
		return Plugin_Handled;
	}
	else if (!IsPlayerAlive(target))
	{
		PrintToChat(client, "[\x0ESwitch Weapon\x01] \x07That player is dead!");
		return Plugin_Handled;
	}
	else if (!IsPlayerAlive(client))
	{
		PrintToChat(client, "[\x0ESwitch Weapon\x01] \x07You are dead!");
		return Plugin_Handled;
	}
	else if (!GetPlayerWeaponSlot(target, 0))
	{
		PrintToChat(client, "[\x0ESwitch Weapon\x01] \x07Target doesn't have a weapon to switch!");
		return Plugin_Handled;
	}
	/** Exec command**/
	
	if (!IsPlayerAlive(client))
	{
		PrintToChat(client, "[\x0EAlert!\x01]\x07 Cancelled: You are dead!");
		return Plugin_Handled;
	}
	else if (!IsPlayerAlive(target))
	{
		PrintToChat(target, "[\x0EAlert!\x01]\x07 Cancelled: That player is dead!");
		return Plugin_Handled;
	}
	
	if (PreTakeWeapon(client, target))
	{
		RemovePlayerItem(client, g_iWeapon[client]);
		AcceptEntityInput(g_iWeapon[client], "Kill");
		exec_TakeWeapon(client, target);
	} 
	else if (!PreTakeWeapon(client, target))
	{ 
		exec_TakeWeapon(client, target);
	}
	
}

stock bool:PreTakeWeapon(player1, player2)
{
	g_iWeapon[player1] = GetPlayerWeaponSlot(player1, 0);
	if (g_iWeapon[player1] == -1) { return false; } else { return true; }
}

exec_TakeWeapon(player1, player2)
{
	new Handle:DataPack = CreateDataPack();
	WritePackCell(DataPack, player1);
	WritePackCell(DataPack, player2);
	
	
	g_iWeapon[player2] = GetPlayerWeaponSlot(player2, 0);
	if (g_iWeapon[player2] == -1) { return; }
	
	new String:szClassID[64];
	GetEdictClassname(g_iWeapon[player2], szClassID, sizeof(szClassID));
	
	WritePackString(DataPack, szClassID);
	CS_DropWeapon(player2, g_iWeapon[player2], false, true);
	CreateDataTimer(0.1, EquipWeapon, DataPack);
}

// trying to pass the target into a timer callback
public Action:EquipWeapon(Handle:timer, Handle:DataPack)
{
	new client;  
	new target; 
	decl String:szClassID[64];
	ResetPack(DataPack);
	
	client = ReadPackCell(DataPack);
	target = ReadPackCell(DataPack);
	ReadPackString(DataPack, szClassID, sizeof(szClassID));
	
	if (IsPlayerAlive(client))
	{

		//decl String:newWeapon[64];
		//Format(newWeapon, sizeof(newWeapon), szClassID);
		
		PrintToChatAll("client: %s", client);
		PrintToChatAll("target: %s", target);
		PrintToChatAll("string: %s", szClassID);
		
		new Float:clientvec[3];
		GetClientAbsOrigin(client, clientvec);
		//TeleportEntity(newWeapon, clientvec, NULL_VECTOR, NULL_VECTOR);
		
		EquipPlayerWeapon(client, g_iWeapon[client]);
		EquipPlayerWeapon(target, g_iWeapon[target]);
		
		//SetEntPropEnt(client, Prop_Send, "m_hActiveWeapon", szClassID); // maybe change this variable to szClassID idk
		//SetEntPropEnt(target, Prop_Send, "m_hActiveWeapon", szClassID); // maybe change this variable to szClassID idk
		CloseHandle(DataPack);
	}
}

Last edited by bally; 09-15-2015 at 17:37.
bally is offline
SoulSharD
Member
Join Date: Oct 2013
Location: United Kingdom
Old 09-16-2015 , 04:47   Re: Help on code pls
Reply With Quote #2

Remember to use ResetPack() before reading any pack data.
__________________

SoulSharD is offline
bally
Senior Member
Join Date: Aug 2015
Old 09-16-2015 , 07:09   Re: Help on code pls
Reply With Quote #3

I did, look at my last function
bally is offline
SoulSharD
Member
Join Date: Oct 2013
Location: United Kingdom
Old 09-16-2015 , 07:23   Re: Help on code pls
Reply With Quote #4

PHP Code:
exec_TakeWeapon(player1player2)
{
    
g_iWeapon[player2] = GetPlayerWeaponSlot(player20);
    if (
g_iWeapon[player2] == -1) { return; }
    
    new 
String:szClassID[64];
    
GetEdictClassname(g_iWeapon[player2], szClassIDsizeof(szClassID));
    
CS_DropWeapon(player2g_iWeapon[player2], falsetrue);
    
    new 
Handle:DataPack;
    
CreateDataTimer(0.1EquipWeaponDataPack);
    
    
WritePackCell(DataPackplayer1);
    
WritePackCell(DataPackplayer2);
    
WritePackString(DataPackszClassID);
}

// trying to pass the target into a timer callback
public Action:EquipWeapon(Handle:timerHandle:DataPack)
{
    
ResetPack(DataPack);
    new 
client;  
    new 
target
    
decl String:szClassID[64];
    
    
client ReadPackCell(DataPack);
    
target ReadPackCell(DataPack);
    
ReadPackString(DataPackszClassIDsizeof(szClassID));
    
    if (
IsPlayerAlive(client))
    {

        
//decl String:newWeapon[64];
        //Format(newWeapon, sizeof(newWeapon), szClassID);
        
        
PrintToChatAll("client: %s"client);
        
PrintToChatAll("target: %s"target);
        
PrintToChatAll("string: %s"szClassID);
        
        new 
Float:clientvec[3];
        
GetClientAbsOrigin(clientclientvec);
        
//TeleportEntity(newWeapon, clientvec, NULL_VECTOR, NULL_VECTOR);
        
        
EquipPlayerWeapon(clientg_iWeapon[client]);
        
EquipPlayerWeapon(targetg_iWeapon[target]);
        
        
//SetEntPropEnt(client, Prop_Send, "m_hActiveWeapon", szClassID); // maybe change this variable to szClassID idk
        //SetEntPropEnt(target, Prop_Send, "m_hActiveWeapon", szClassID); // maybe change this variable to szClassID idk
        
CloseHandle(DataPack);
    }

Try that.

If memory serves, you don't need to bother the the CreateDataPack() function. And everything needs to be packed after passing the handle to the timer.
__________________


Last edited by SoulSharD; 09-16-2015 at 07:24.
SoulSharD is offline
bally
Senior Member
Join Date: Aug 2015
Old 09-16-2015 , 08:19   Re: Help on code pls
Reply With Quote #5

yea, I'm about to test this, I'll tell you if it works or not, thanks.

Last edited by bally; 09-16-2015 at 08:19.
bally is offline
bally
Senior Member
Join Date: Aug 2015
Old 09-16-2015 , 08:25   Re: Help on code pls
Reply With Quote #6

@soulsharD it works man, thanks.

Last edited by bally; 09-16-2015 at 08:26.
bally is offline
Reply


Thread Tools
Display Modes

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 20:33.


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