Raised This Month: $ Target: $400
 0% 

[CS:GO] Give Weapon Not Working


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
clarkeylogic
Member
Join Date: Jun 2015
Old 07-17-2015 , 16:12   [CS:GO] Give Weapon Not Working
Reply With Quote #1

I am trying to write a simple plugin that gives clients weapons on spawn. My code is very basic, but for some reason everyone only got guns for the first round, and although they looked like glocks, they fired like deagles and started with 250 bullets, why?

PHP Code:
#include <sourcemod>
#include <smlib>
#include <cstrike>
#pragma newdecls required

public Plugin myinfo =
{
    
name "Spawn Weapon",
    
author "Clarkey",
    
description "Gives players weapons on spawn",
    
version "1.0",
    
url "http://finalrespawn.com/"
}

public 
void OnPluginStart()
{
    
HookEvent("player_spawned"Event_PlayerSpawned);
}

public 
void Event_PlayerSpawned(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
int team GetClientTeam(client);
    
    if (
team == CS_TEAM_T)Client_GiveWeapon(client"weapon_glock"true);
    else if (
team == CS_TEAM_CT)Client_GiveWeapon(client"weapon_hkp2000"true);

clarkeylogic is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 07-17-2015 , 16:31   Re: [CS:GO] Give Weapon Not Working
Reply With Quote #2

Try the player_spawn event instead
Miu is offline
Kasea
Member
Join Date: Feb 2015
Old 07-18-2015 , 03:13   Re: [CS:GO] Give Weapon Not Working
Reply With Quote #3

like Miu said use player_spawn, and try using EventHookMode_Post.

Also you should check if the client has a weapon from before so it doesn't "double" spawn in a sense.
Kasea is offline
Michalplyoutube
Veteran Member
Join Date: Jan 2013
Location: Tank Carrier in Mannhatt
Old 07-18-2015 , 03:55   Re: [CS:GO] Give Weapon Not Working
Reply With Quote #4

Also create timer with delay 0.1s cos some stuff can be not set yet by game
__________________
The plugin developer of TF2BWR Reborn
And a TF2 Player
Michalplyoutube is offline
clarkeylogic
Member
Join Date: Jun 2015
Old 09-08-2015 , 07:03   Re: [CS:GO] Give Weapon Not Working
Reply With Quote #5

For anyone who comes across this post in the future, this was the final source I used.

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

#pragma semicolon 1
#pragma newdecls required

public Plugin myinfo = {
    
name "Spawn Weapons",
    
author "Clarkey",
    
description "Gives weapons on spawn",
    
version "1.0",
    
url "http://finalrespawn.com"
};

public 
void OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawn);
}

public 
Action Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    
int ClientUserId GetEventInt(event"userid");
    
int Client GetClientOfUserId(ClientUserId);
    
    
Client_RemoveAllWeapons(Client);
    
CreateTimer(0.1Timer_GiveWeaponsClientUserId);
}

public 
Action Timer_GiveWeapons(Handle timerany data)
{
    
int Client GetClientOfUserId(data);
    
int Team GetClientTeam(Client);
    
    if (
Team == CS_TEAM_CT)
    {
        
GivePlayerItem(Client"weapon_hkp2000");
        
GivePlayerItem(Client"weapon_knife");
    }
    else if (
Team == CS_TEAM_T)
    {
        
GivePlayerItem(Client"weapon_glock");
        
GivePlayerItem(Client"weapon_knife_t");
    }

clarkeylogic is offline
nhnkl159
Senior Member
Join Date: Jul 2012
Location: Israel 3>
Old 09-08-2015 , 07:10   Re: [CS:GO] Give Weapon Not Working
Reply With Quote #6

player_spawned ?

try to hook :
player_spawn
__________________
nhnkl159 is offline
Send a message via Skype™ to nhnkl159
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 09-08-2015 , 07:13   Re: [CS:GO] Give Weapon Not Working
Reply With Quote #7

Quote:
Originally Posted by nhnkl159 View Post
player_spawned ?

try to hook :
player_spawn
He already fixed that in his latest post
Addicted. is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 09-08-2015 , 18:17   Re: [CS:GO] Give Weapon Not Working
Reply With Quote #8

It was fixed by using GivePlayerItem instead of Client_GiveWeapon.

Client_GiveWeapon probably uses CreateItemByClassname which requires m_iItemDefinition to be set before DispatchSpawn is called.
__________________
Neuro Toxin 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 03:37.


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