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

Players > 1 &&/|| Map Change breaking function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xXNewGuyXx
Member
Join Date: Jun 2016
Old 01-31-2017 , 23:16   Players > 1 &&/|| Map Change breaking function
Reply With Quote #1

Solutions for this thread:
1.)You shouldn't use a single global integer to represent all clients, instead pass the client as data: Pass in userid : GetClientUserId(client)/GetClientOfUserId(userid)

2.) It is important to understand that Weapon name strings for events differ from weapon name strings for entities (applicable on player_death Hook).

Last edited by xXNewGuyXx; 02-02-2017 at 09:01. Reason: Solved:
xXNewGuyXx is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 01-31-2017 , 23:38   Re: Players > 1 &&/|| Map Change breaking function
Reply With Quote #2

You shouldn't use a single global integer to represent all clients, instead pass the client as data.

PHP Code:
CreateTimer(1.0Timer_MyFunctionclient);

public 
Action Timer_MyFunction(Handle timerint client)
{
    
// ...

Edit: Chaosxk is correct, you should pass a userid in the code above as client indexes are reused frequently and arbitrarily.

Last edited by Kolapsicle; 01-31-2017 at 23:59.
Kolapsicle is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 01-31-2017 , 23:44   Re: Players > 1 &&/|| Map Change breaking function
Reply With Quote #3

^ Pass in userid : GetClientUserId(client)/GetClientOfUserId(userid)
__________________
Chaosxk is offline
xXNewGuyXx
Member
Join Date: Jun 2016
Old 02-01-2017 , 10:46   Re: Players > 1 &&/|| Map Change breaking function
Reply With Quote #4

Hello,

Thank you so much for your reply. I have changed the SpawnWait timer to:
PHP Code:
public Action SpawnWait(Handle timerint userid)
{
    new 
client GetClientOfUserId(userid);
    
GiveWeapons(client);
    
CPrintToChatAll("{grey}SpawnWait Handle timer: FIRED");

But now it doesn't seem to be working even solo and I'm seeing errors in server console:
PHP Code:
[SMNative "IsClientInGame" reportedClient index 0 is invalid
[SMDisplaying call stack trace for plugin "Plugin.smx":
[
SM]    [0]    Line 230Plugin.sp::GiveWeapons()
[
SM]    [1]    Line 189Plugin.sp::SpawnWait() 
Am I missing something?
xXNewGuyXx is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 02-01-2017 , 10:57   Re: Players > 1 &&/|| Map Change breaking function
Reply With Quote #5

Are you creating your timer like this?

PHP Code:
CreateTimer(0.1SpawnWaitGetClientUserId(client)); 
Make sure to also exclude invalid client ranges such as < 1 and > MaxClients

PHP Code:
    if (client <= MaxClients && IsClientInGame(client))
    {
        
// ...
    


Last edited by Kolapsicle; 02-01-2017 at 11:01.
Kolapsicle is offline
xXNewGuyXx
Member
Join Date: Jun 2016
Old 02-01-2017 , 11:08   Re: Players > 1 &&/|| Map Change breaking function
Reply With Quote #6

When I create the timer like that, client becomes undefined because the rest of the function is using client_id from
PHP Code:
public Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client_id GetClientOfUserId(GetEventInt(event"userid"));

xXNewGuyXx is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 02-01-2017 , 11:21   Re: Players > 1 &&/|| Map Change breaking function
Reply With Quote #7

PHP Code:
CreateTimer(0.1SpawnWaitGetEventInt(event"userid"));

public 
Action SpawnWait(Handle timerint userid) {

    
int client GetClientOfUserId(userid);


Addicted. is offline
xXNewGuyXx
Member
Join Date: Jun 2016
Old 02-01-2017 , 12:16   Re: Players > 1 &&/|| Map Change breaking function
Reply With Quote #8

Thanks oaaron, this is much more stable.

However, after about 10 map changes, an rtv caused one player to spawn with weapons the stripper was supposed to get rid of, even though the players output was:
PHP Code:
Event_SpawnFIRED
(StripAllWeapons): FIRED
SpawnWait Handle timer
FIRED
(GiveWeapons): FIRED 
Looking at the server console, I am now seeing the following errors:
[SM] Native "AcceptEntityInput" reported: Entity 85 (85) is not a CBaseEntity
[SM] [0] Line 195, Plugin.sp::KillStripper()
xXNewGuyXx is offline
Kolapsicle
Senior Member
Join Date: Oct 2014
Old 02-01-2017 , 13:30   Re: Players > 1 &&/|| Map Change breaking function
Reply With Quote #9

Is there any reason why you can't strip weapons with a loop in the player_spawn event callback?

PHP Code:
void StripClientWeapons(int client)
{
    for (
int i 05i++) {
        
int weapon GetPlayerWeaponSlot(clienti);
        if (
weapon != -1) {
            
AcceptEntityInput(weapon"Kill");
        }
    }

Kolapsicle is offline
xXNewGuyXx
Member
Join Date: Jun 2016
Old 02-01-2017 , 13:57   Re: Players > 1 &&/|| Map Change breaking function
Reply With Quote #10

Hey there Kolapsicle,

Your suggestion compiles fine, but it doesn't seem to be working in game. There are no errors in the console that I can see either.
xXNewGuyXx 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 02:31.


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