Raised This Month: $32 Target: $400
 8% 

Solved OnClientPutInServer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SweetDickWilly
Junior Member
Join Date: Nov 2018
Location: Las Vegas, Nevada
Old 01-11-2020 , 02:40   OnClientPutInServer
Reply With Quote #1

Hello,

I am a sourcemod scripting noob and I am attempting to get familiar with the framework and the sourcepawn language. I am trying to write a script that prints "Hey bitch..." into the game chat once a player loads into the game. So Far I am having difficulties achieving this task by attempting to use the forward OnClientPutInServer(). I desperately need to master this function if I am to ever advance in making my plugin.

I can get the string to print to game chat OnPluginStart() but cannot get any love with OnClientPutInServer(). I have tried OnClientPostAdminCheck() and OnClientConnected() and still no luck. Below is my code, please fellow coders guide me and show me the error in my ways, you are my only hope.


#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <clients>
#include <halflife>

#pragma semicolon 1
#pragma newdecls required


public Plugin myinfo =
{
name = "football",
author = "Sweet Dick Willy (Innovoeb)",
description = "American football mod plugin for CS:GO. Converted from WhoKid's 1.6 AFM mod.'",
version = "0.01",
url = ""
};

public void OnClientPutInServer(int client)
{
HeyBitch();
}

// function that prints 'Hey Bitch, ....' to game chat for all players
public Action HeyBitch()
{
PrintToChatAll("Hey Bitch, What's Happenin");
}

Last edited by SweetDickWilly; 01-13-2020 at 00:51.
SweetDickWilly is offline
Indarello
Senior Member
Join Date: Nov 2015
Location: Russia
Old 01-11-2020 , 15:16   Re: OnClientPutInServer
Reply With Quote #2

Use 2 sec timer after OnClientPostAdminCheck
Indarello is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-11-2020 , 16:10   Re: OnClientPutInServer
Reply With Quote #3

You want them to see it in the chat?

Hook the player spawn event, then do IsPlayerAlive(). If player alive, print the text.

You'll need to keep track of whether you've already printed it per-player, clearing that var on player disconnect or join.
__________________

Last edited by ddhoward; 01-11-2020 at 16:10.
ddhoward is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-11-2020 , 21:23   Re: OnClientPutInServer
Reply With Quote #4

or simply create a 5 seconds timer after OnClientPostAdminCheck (most plugins do this),
No need for message to be in next frame after client connects
Sometimes delaying the message is more effective for the user to see the message.

player_spawn event fires a lot of times for the same player e.g while going idle (on L4D2 at least)
__________________

Last edited by Marttt; 01-11-2020 at 21:24.
Marttt is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 01-12-2020 , 05:34   Re: OnClientPutInServer
Reply With Quote #5

This is tricky and requires fine tuning as each game and scenario is different. I have used OnClientPostAdminCheck and player_spawn event in different plugins. Both with a delay of a second or more, sometimes more is needed. I would suggest looking at various advertisement or welcome message plugins to get more of an idea, and of course testing multiple conditions.

Quote:
Originally Posted by Marttt View Post
player_spawn event fires a lot of times for the same player e.g while going idle (on L4D2 at least)
I've noticed player_spawn can also fire before round_start, adding to more confusion.

Problem is when loading from a map change, the server may be waiting for all clients to load before they're actually in-game. The player_spawn event might of fired already, so the message may appear in chat sometime before they're in game and no longer visible unless they open chat and scroll up. This is where you have to play around and test for which method and delay is best suited.
__________________
Silvers is offline
SweetDickWilly
Junior Member
Join Date: Nov 2018
Location: Las Vegas, Nevada
Old 01-13-2020 , 00:47   Re: OnClientPutInServer
Reply With Quote #6

Thank you for the responses fellers. I set a 5 second timer within OnClientPostAdminCheck() and it works like a charm. Again, thank you to all for your help!
SweetDickWilly is offline
SweetDickWilly
Junior Member
Join Date: Nov 2018
Location: Las Vegas, Nevada
Old 01-13-2020 , 00:48   Re: OnClientPutInServer
Reply With Quote #7

Thank you sir, it worked like a charm.
SweetDickWilly is offline
enjoi.
Veteran Member
Join Date: Mar 2011
Old 05-12-2020 , 04:49   Re: OnClientPutInServer
Reply With Quote #8

American Football Mod for CS:GO?

Sign me up!
__________________
Block Maker v6.0 []
Point Slay v3.0 []
Contact [ PM ]
enjoi. 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 17:09.


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