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

[Help] Duplicating weapon and giving it to client


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bally
Senior Member
Join Date: Aug 2015
Old 09-11-2015 , 15:01   [Help] Duplicating weapon and giving it to client
Reply With Quote #1

Hi, I just recently started out on SM, I was wondering if you guys could explain a little bit for me about the mechanics of the duplication of the knife, thats is in this plugin from Neuro Toxin, this is what I got so far:

*His/Her plugin is in the attachments btw*

My main goal here is to do the same effect as this plugin, but for the Primary Weapon & only duplicate the target weapon and give the copy to the client... thanks!

Code:
/* Plugin Template generated by Pawn Studio */

#include <sourcemod>
#include <sdktools>
#include <cstrike>
#pragma semicolon 1

new bool:DisableSwitch[MAXPLAYERS + 1];
new iWeapon[MAXPLAYERS + 1];

public Plugin:myinfo = 
{
	name = "!takeweapon",
	author = "Grandpa",
	description = "n00b",
	version = "101",
	url = "http://steamcommunity.com/id/grandpakudos/"
}

 /***********************************
 * 1- create a command				*
 * 2- grab target					*
 * 3- grab primary weapon of target	*
 * 4- gib it to me					*
 * 5- yolo							*
 ***********************************/
 
public OnPluginStart()
{
	init();
}

stock init()
{
	HookEvent("round_start", Event_RoundStart);
	RegConsoleCmd("sm_takeweapon", command_takeWeapon, "woompa stomp!");
	RegConsoleCmd("sm_takeweaponoff", Command_Switch, "disables the ability for other people to grab your weapon.");

}

public OnClientPutInServer(client)
{
	DisableSwitch[client] = false;
}

public Action:Command_Switch(client, args)
{
	DisableSwitch[client] = !DisableSwitch[client];
	if(DisableSwitch[client])
	{
		PrintToChat(client, "[\x0EAlert!\x01] Your dragonlore is safe bud!");
	}
	else
	{
		PrintToChat(client, "[\x0EAlert!\x01] You have \x06enabled\x01 switching!");
	}
	return Plugin_Handled;
}

public Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast) 
{
	// grab wep
	for(new i = 1; i < MaxClients; i++)
	{
		if(IsClientInGame(i))
		{
			iWeapon[i] = GetPlayerWeaponSlot(i, 0);
		}
		else
		{
			iWeapon[i] = -1;
		}
	}
}

public Action:command_takeWeapon(client, args)
{
	if(args < 1)
	{
		PrintToChat(client, "[\x0EAlert!\x01] Usage: sm_takeweapon <player>");
		return Plugin_Handled;
	}
	new String:arg[32];
	GetCmdArg(1, arg, sizeof(arg));

	new target = FindTarget(client, arg, false, false);
	if (target == -1)
	{
		PrintToChat(client, "[\x0EAlert!\x01] \x07Cannot find player!");
		return Plugin_Handled;
	}
	//else if(target == client)
	//{
	//	PrintToChat(client, "[\x0EAlert!\x01] \x07You cannot swap knives with yourself!");
	//	return Plugin_Handled;
	//}
	else if(DisableSwitch[target])
	{
		PrintToChat(client, "[\x0EAlert!\x01] \x07That person has disabled switching!");
		return Plugin_Handled;
	}
	else if(!IsPlayerAlive(target))
	{
		PrintToChat(client, "[\x0EAlert!\x01] \x07That player is dead!");
		return Plugin_Handled;
	}
	else if(!IsPlayerAlive(client))
	{
		PrintToChat(client, "[\x0EAlert!\x01] \x07You are dead!");
		return Plugin_Handled;
	}
	
	else if(!GetPlayerWeaponSlot(target, 0))
	{
		PrintToChat(client, "[\x0EAlert!\x01] \x07He does not have a weapon!");
		return Plugin_Handled;
	}

	PrintToChat(client, "[\x0EAlert!\x01] You are using the weapon of: \x09%N", target);
	TakeWeapon(client, target);
	
	return Plugin_Handled;
}


TakeWeapon(player1, player2)
{
	if(!IsPlayerAlive(player1))
	{
		PrintToChat(player1, "[\x0EAlert!\x01]\x07 Cancelled: You are dead!");
		return;
	}
	else if(!IsPlayerAlive(player2))
	{
		PrintToChat(player1, "[\x0EAlert!\x01]\x07 Cancelled: That player is dead!");
		return;
	}

	new weapon1 = GetPlayerWeaponSlot(player2, 0);
	new weapon2 = GetPlayerWeaponSlot(player1, 0);

	
	if(weapon2 == -1)
	{
		PrintToChat(player1, "[\x0EAlert\x01]\x07 Cancelled: He doesn't have a weapon to switch!");
		return;
	}

	
	RemovePlayerItem(player1, weapon1);
	
	

	iWeapon[player1] = knife2;
	iWeapon[player2] = knife1;

	CreateTimer(0.1, Equipweapon, player1);
}

stock tfmWeapon(client, target)
{
	// just to make sure there's no breach...
	new targetwep = GetPlayerWeaponSlot(target, 0);
	if (targetwep == -1)
	{
		ReplyToCommand(client, "[SM] Target does not have a weapon!");
		return;
	}
	
	// Magic trick 

	
}
Attached Files
File Type: sp Get Plugin or Get Source (knifeswapper (3).sp - 169 views - 22.0 KB)

Last edited by bally; 09-11-2015 at 15:57.
bally is offline
bally
Senior Member
Join Date: Aug 2015
Old 09-11-2015 , 23:15   Re: [Help] Duplicating weapon and giving it to client
Reply With Quote #2

;_; guess I should give more info about my problem.
bally is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 09-12-2015 , 11:46   Re: [Help] Duplicating weapon and giving it to client
Reply With Quote #3

PHP Code:
void DuplicatePrimary(int aint b)
{
    
int weapon GetPlayerWeaponSlot(a0);
    
    if(
weapon == -1)
        return;
    
    
char classname[64];
    
GetEntityClassname(weaponclassnamesizeof(classname));
    
    
GivePlayerItem(bclassname);

Miu is offline
bally
Senior Member
Join Date: Aug 2015
Old 09-12-2015 , 12:15   Re: [Help] Duplicating weapon and giving it to client
Reply With Quote #4

Hi, Miu. Will this snippet keep the weapon skin?
bally is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 09-12-2015 , 13:28   Re: [Help] Duplicating weapon and giving it to client
Reply With Quote #5

no, you'd need to use this stuff i guess, don't really know since i don't play csgo
Miu is offline
bally
Senior Member
Join Date: Aug 2015
Old 09-12-2015 , 13:37   Re: [Help] Duplicating weapon and giving it to client
Reply With Quote #6

maybe if we drop the weapon of the target teleport the entity to the client and equip the weapon to client and then refresh the target weapon?

Last edited by bally; 09-12-2015 at 13:42.
bally is offline
DabuDos
Junior Member
Join Date: Feb 2015
Location: Germany
Old 09-12-2015 , 17:01   Re: [Help] Duplicating weapon and giving it to client
Reply With Quote #7

You basicly only have to give the item to Client #1 but then Equip it to Client #2.

PHP Code:
new Item GivePlayerItem(ClientToTakeSkinFrom"weapon_ak47");
EquipPlayerWeapon(ClientToGiveTheSkinToItem); 
Simply replace the two Client Variables with your ones. Thats how it works for me tho.
And yes that works for every weapon afaik.

Last edited by DabuDos; 09-12-2015 at 17:04.
DabuDos is offline
bally
Senior Member
Join Date: Aug 2015
Old 09-12-2015 , 17:08   Re: [Help] Duplicating weapon and giving it to client
Reply With Quote #8

Quote:
Originally Posted by DabuDos View Post
You basicly only have to give the item to Client #1 but then Equip it to Client #2.

PHP Code:
new Item GivePlayerItem(ClientToTakeSkinFrom"weapon_ak47");
EquipPlayerWeapon(ClientToGiveTheSkinToItem); 
Simply replace the two Client Variables with your ones. Thats how it works for me tho.
And yes that works for every weapon afaik.
Could you please clarify a bit more what you mean..

This is what I have, I dropped the target weapon and uh gave them the weapon again and then I basically teleported the other entity from target to the client vec
Code:
   decl String:buffer[64];
    GetEntityClassname(weapon2, buffer, sizeof(buffer));
    PrintToChatAll("the name is: %s", buffer); // remove this
	g_iwep[client] = weapon2;
	GivePlayerItem(target, buffer);
	
	new Float:clientvec[3], Float:targetvec[3];
	GetEntPropVector(client, Prop_Send, "m_vecOrigin", clientvec);
	
	TeleportEntity(weapon2, clientvec, NULL_VECTOR, NULL_VECTOR);
		EquipPlayerWeapon(client, weapon2);
		
	SetEntPropEnt(client, Prop_Send, "m_hActiveWeapon", g_iwep[client]);

Last edited by bally; 09-12-2015 at 17:10.
bally is offline
DabuDos
Junior Member
Join Date: Feb 2015
Location: Germany
Old 09-12-2015 , 17:11   Re: [Help] Duplicating weapon and giving it to client
Reply With Quote #9

Quote:
Originally Posted by bally View Post
Could you please clarify a bit more what you mean..

This is what I have so far
Code:
   decl String:buffer[64];
    GetEntityClassname(weapon2, buffer, sizeof(buffer));
    PrintToChatAll("the name is: %s", buffer); // remove this
	g_iwep[client] = weapon2;
	GivePlayerItem(target, buffer);
	
	new Float:clientvec[3], Float:targetvec[3];
	GetEntPropVector(client, Prop_Send, "m_vecOrigin", clientvec);
	
	TeleportEntity(weapon2, clientvec, NULL_VECTOR, NULL_VECTOR);
		EquipPlayerWeapon(client, weapon2);
		
	SetEntPropEnt(client, Prop_Send, "m_hActiveWeapon", g_iwep[client]);
You don't have to teleport the entity if you are equiping it to the target, since it's forced to the client.
Just do what I wrote upper and remove the teleporting part, that *should* work.

What excactly are you trying to do with that?
Do you want to give everyone an AWP with your skin on round start, or when they buy an ak for example,
they get the skin from another one (maybe with a selection)?

Last edited by DabuDos; 09-12-2015 at 17:14.
DabuDos is offline
bally
Senior Member
Join Date: Aug 2015
Old 09-12-2015 , 17:16   Re: [Help] Duplicating weapon and giving it to client
Reply With Quote #10

Quote:
Originally Posted by DabuDos View Post
You don't have to teleport the entity if you are equiping it to the target, since it's forced to the client.
Just do what I wrote upper and remove the teleporting part, that *should* work.

What excactly are you trying to do with that?
Do you want to give everyone an AWP with your skin on round start, or when they buy an ak for example,
they get the skin from another one (maybe with a selection)?
it seems to give me a default primary skin I tried that before
bally 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 20:53.


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