AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [Help] Duplicating weapon and giving it to client (https://forums.alliedmods.net/showthread.php?t=271398)

bally 09-11-2015 15:01

[Help] Duplicating weapon and giving it to client
 
1 Attachment(s)
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

       
}


bally 09-11-2015 23:15

Re: [Help] Duplicating weapon and giving it to client
 
;_; guess I should give more info about my problem.

Miu 09-12-2015 11:46

Re: [Help] Duplicating weapon and giving it to client
 
PHP Code:

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



bally 09-12-2015 12:15

Re: [Help] Duplicating weapon and giving it to client
 
Hi, Miu. Will this snippet keep the weapon skin?

Miu 09-12-2015 13:28

Re: [Help] Duplicating weapon and giving it to client
 
no, you'd need to use this stuff i guess, don't really know since i don't play csgo

bally 09-12-2015 13:37

Re: [Help] Duplicating weapon and giving it to client
 
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?

DabuDos 09-12-2015 17:01

Re: [Help] Duplicating weapon and giving it to client
 
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.

bally 09-12-2015 17:08

Re: [Help] Duplicating weapon and giving it to client
 
Quote:

Originally Posted by DabuDos (Post 2342338)
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]);


DabuDos 09-12-2015 17:11

Re: [Help] Duplicating weapon and giving it to client
 
Quote:

Originally Posted by bally (Post 2342343)
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)?

bally 09-12-2015 17:16

Re: [Help] Duplicating weapon and giving it to client
 
Quote:

Originally Posted by DabuDos (Post 2342345)
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


All times are GMT -4. The time now is 17:13.

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