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

Solved Trying to give players a weapon when they spawn (CS:GO)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dasbunny
New Member
Join Date: May 2019
Location: Vorarlberg, Austria
Old 05-13-2019 , 07:15   Trying to give players a weapon when they spawn (CS:GO)
Reply With Quote #1

Hello,
I'm trying to make a plugin that gives players a taser when they spawn if they want to have one. On my testserver some weird things happen when testing it.
I'm testing using a dedicated server on a second pc with nothing else installed. When I connect to the server it's a 5v5 competitive filled with bots. I never receive a taser, but 7-8 of the bots do (leaving 1-2 other bots without taser aswell). The plugin prints messages into the console when a player spawn event is fired and also when it gives out a taser, both including the target id. It always says it gave me a taser, but I don't receive it. Also sometimes it says a player is not ingame, but that same id then gets a taser anyways.
I've also tried this with ak47s, it results in the same behavior, except that I can't equip the weapon using slot1 ingame, but instead need to drop my secondary to be automaticially to switched it. After that the weapon works normally.
I have no idea what could cause this, other than maybe GivePlayerItem requiring another id and it just happens to work by chance for some of the bots. I couldn't find anything that would hint to this being the case though.

Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
#include "include/timers.inc"

public Plugin myinfo = 
{
	name = "testplugin",
	author = "dasBunny",
	description = "taser drop test",
	version = "1.2",
	url = "_"
};

public void OnPluginStart(){
	HookEvent("round_end", Event_RoundEnd);
	HookEvent("player_spawn", Event_PlayerSpawn,EventHookMode_Post);
}

public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast) {
	PrintToServer("TESTPLUGIN: round_end Event fired");
}

public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast){
	int userid = event.GetInt("userid");
	PrintToServer("TESTPLUGIN: player_spawn Event fired %d",userid);
	if(!IsClientInGame(userid)){
		PrintToServer("TESTPLUGIN: Aborted taser drop %d",userid);
		return;
	}
	CreateTimer(0.5, GiveTaser, userid, TIMER_FLAG_NO_MAPCHANGE);
}

public Action GiveTaser(Handle timer, int userid){
	int client=GetClientOfUserId(userid);
	GivePlayerItem(client,"weapon_taser",1);
	PrintToServer("TESTPLUGIN: Dropped taser %d",userid);
}
Attached Files
File Type: sp Get Plugin or Get Source (testplugin.sp - 12 views - 1.1 KB)
File Type: smx testplugin.smx (4.5 KB, 7 views)

Last edited by dasbunny; 05-14-2019 at 11:42. Reason: Fixed part of the problem, updated code
dasbunny is offline
dasbunny
New Member
Join Date: May 2019
Location: Vorarlberg, Austria
Old 05-13-2019 , 08:01   Re: Trying to give players a weapon when they spawn (CS:GO)
Reply With Quote #2

Apparently I was right and I need to use the client and not the id for GivePlayerItem. But the problem of not being able to switch to the weapon given remains.
dasbunny is offline
Ilusion9
Senior Member
Join Date: Jun 2018
Location: Romania
Old 05-14-2019 , 06:31   Re: Trying to give players a weapon when they spawn (CS:GO)
Reply With Quote #3

PHP Code:

public void Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    if (
event.GetInt("teamnum"))
    {
        
int client GetClientOfUserId(event.GetInt("userid"));
    
        if (
client)
        {
            
GivePlayerItem(client"weapon_taser");
        }
    }

__________________
Ilusion9 is offline
dasbunny
New Member
Join Date: May 2019
Location: Vorarlberg, Austria
Old 05-14-2019 , 11:42   Re: Trying to give players a weapon when they spawn (CS:GO)
Reply With Quote #4

Quote:
Originally Posted by Ilusion9 View Post
PHP Code:

public void Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    if (
event.GetInt("teamnum"))
    {
        
int client GetClientOfUserId(event.GetInt("userid"));
    
        if (
client)
        {
            
GivePlayerItem(client"weapon_taser");
        }
    }

Thank you, I got it working
dasbunny 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 12:40.


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