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

Remove/give weapons at round_start


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
farawayf
Senior Member
Join Date: Jan 2019
Old 01-21-2019 , 13:39   Remove/give weapons at round_start
Reply With Quote #1

Hello
I want to make plugin which removes all players primary and secondary weapons at round_start and gives m4a1/deagle to all. But plugin does not work. Also compiles with 3 warnings 217: loose indentation at line 15,24,30.

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

public void OnPluginStart()
{
    
HookEvent("round_start"Give_WeaponEventHookMode_Pre);
}

public 
Action Give_Weapon(Handle:event,const String:name[],bool:dontBroadcast)
{
    new 
client_id GetEventInt(event"userid");
    new 
client GetClientOfUserId(client_id);
    
    if(
IsPlayerAlive(client))
    {
        
int entity GetPlayerWeaponSlot(client1);
        if(
entity != -1)
        
AcceptEntityInput(entity"Kill");    

        
RequestFrame(RequestFrame_Callbackclient);
    }

    return 
Plugin_Handled;
}

public 
void RequestFrame_Callback(int client)
{
    
GivePlayerItem(client"weapon_m4a1");
    
GivePlayerItem(client"weapon_deagle");


Last edited by farawayf; 01-21-2019 at 13:39.
farawayf is offline
Indarello
Senior Member
Join Date: Nov 2015
Location: Russia
Old 01-21-2019 , 14:07   Re: Remove/give weapons at round_start
Reply With Quote #2

You try get clientid from ROUND START
not PLAYER_SPAWN
Also
1) You dont need request frame
2) I think eventhook post will be better
3) there maybe some cvars for start weapons
4) you remove only pistol, maybe player can have another weapon from prev round? Or you have cvar reset weapons?

Last edited by Indarello; 01-21-2019 at 14:08.
Indarello is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 01-21-2019 , 14:54   Re: Remove/give weapons at round_start
Reply With Quote #3

Quote:
Originally Posted by Indarello View Post
You try get clientid from ROUND START
not PLAYER_SPAWN
Also
1) You dont need request frame
2) I think eventhook post will be better
3) there maybe some cvars for start weapons
4) you remove only pistol, maybe player can have another weapon from prev round? Or you have cvar reset weapons?
PHP Code:
public void OnPluginStart()
{
    
HookEvent("player_spawn"Give_WeaponEventHookMode_Pre);
}

public 
Action Give_Weapon(Handle:event,const String:name[],bool:dontBroadcast)
{
    new 
client_id GetEventInt(event"userid");
    new 
client GetClientOfUserId(client_id);
    
    if(
GetClientTeam(client) < 2)
    {
        return;
    }
    if(!
IsPlayerAlive(client))
    {
        return;
    }
    
    
RemovePlayerItem(client0) && RemovePlayerItem(client1);
    
    
GivePlayerItem(client"weapon_m4a1") && GivePlayerItem(client"weapon_deagle");


What im doing wrong ? it still compile with loose indentation and didnt work.

Last edited by farawayf; 01-21-2019 at 14:56.
farawayf is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 01-21-2019 , 14:56   Re: Remove/give weapons at round_start
Reply With Quote #4

https://forums.alliedmods.net/showpo...36&postcount=4
__________________
Neuro Toxin is offline
Whai
Senior Member
Join Date: Jul 2018
Old 01-21-2019 , 15:28   Re: Remove/give weapons at round_start
Reply With Quote #5

Why hook before the round start ? shouldn't (players) respawn to their spawn once the round start ? If yes, you wanted to give players weapons before the round start but they'll respawn then get their default weapon back.

btw,

Here is the code (don't know if it works or if it can be compiled)


the code you wanted based on your code from the post 1
Spoiler


the new synthax code :
Spoiler


the old synthax :
Spoiler
__________________

Last edited by Whai; 01-21-2019 at 15:29.
Whai is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 01-21-2019 , 16:36   Re: Remove/give weapons at round_start
Reply With Quote #6

Quote:
Originally Posted by Whai View Post
Why hook before the round start ? shouldn't (players) respawn to their spawn once the round start ? If yes, you wanted to give players weapons before the round start but they'll respawn then get their default weapon back.

btw,

Here is the code (don't know if it works or if it can be compiled)


the code you wanted based on your code from the post 1
Spoiler


the new synthax code :
Spoiler


the old synthax :
Spoiler
Compiled without errors, but does not work.
As if ignoring round start.
I even tried to give without removing weapons, but nothing.
On player_spawn works fine. Weird.

upd.
L 01/22/2019 - 00:48:49: [SM] Exception reported: Invalid client index 0
L 01/22/2019 - 00:48:49: [SM] Blaming: test.smx
L 01/22/2019 - 00:48:49: [SM] Call stack trace:
L 01/22/2019 - 00:48:49: [SM] [0] IsPlayerAlive
L 01/22/2019 - 00:48:49: [SM] [1] Line 26, test.sp::Give_Weapon

Last edited by farawayf; 01-21-2019 at 16:39.
farawayf is offline
Indarello
Senior Member
Join Date: Nov 2015
Location: Russia
Old 01-21-2019 , 22:58   Re: Remove/give weapons at round_start
Reply With Quote #7

int client = 1
Indarello is offline
andi67
Veteran Member
Join Date: Mar 2007
Location: Somewhere near you!!!
Old 01-22-2019 , 07:06   Re: Remove/give weapons at round_start
Reply With Quote #8

Oops
__________________
Waiting for HL3,Day of Defeat3 ,but will it ever come? So I'm gonna play COD WW2.>>>>SM_SKINCHOOSER<<<<
>>You need Models for DODS/CSS/CSGO , than click here!!!<<

Last edited by andi67; 01-22-2019 at 07:07.
andi67 is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 01-22-2019 , 09:16   Re: Remove/give weapons at round_start
Reply With Quote #9

Quote:
Originally Posted by Indarello View Post
int client = 1
Thanks! Now it worked
farawayf 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 12:11.


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