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

How to use an event's client in another event? How to store each client?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sereky
Member
Join Date: Aug 2011
Old 02-10-2012 , 06:55   How to use an event's client in another event? How to store each client?
Reply With Quote #1

PHP Code:
new client[MAXPLAYERS 1];

public 
OnPluginStart()
{
    
HookEvent("weapon_fire"OnWeaponFire);
    
HookEvent("round_end"OnRoundEnd);
}

public 
Action:OnWeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
{
    
client[?] = GetClientOfUserId(GetEventInt(event"userid"));
}

public 
Action:OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
*(
how to use here the client of OnWeaponFire event?)

The new client; would save only the last client.

I tried to save each client separately with new client[MAXPLAYERS + 1];, but I don't know how to use it in anohter event.

Last edited by sereky; 05-05-2012 at 16:52.
sereky is offline
Jоnny
Senior Member
Join Date: Jun 2007
Old 02-10-2012 , 07:48   Re: How to use an event's client in another event? How to save each client?
Reply With Quote #2

Code:
new client;

public OnPluginStart()
{
    HookEvent("weapon_fire", OnWeaponFire);
    HookEvent("round_end", OnRoundEnd);
}

public Action:OnWeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
{
    client = GetClientOfUserId(GetEventInt(event, "userid"));
}

public Action:OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
    PrintToChat(client, "Hello, World!");
}  
Jоnny is offline
sereky
Member
Join Date: Aug 2011
Old 02-10-2012 , 07:58   Re: How to use an event's client in another event? How to save each client?
Reply With Quote #3

Quote:
Originally Posted by Jоnny View Post
...
Sorry, I forgot something. I've updated the first post.
sereky is offline
Gate
Junior Member
Join Date: May 2009
Location: Germany
Old 02-10-2012 , 09:15   Re: How to use an event's client in another event? How to save each client?
Reply With Quote #4

You better dont use client as a global Int... You better call it SavedClient to avoid problems with local ints...
Gate is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 02-10-2012 , 10:59   Re: How to use an event's client in another event? How to save each client?
Reply With Quote #5

There is no sense to save player indexs...
you have purpose to use event weapon_fire for some reason ?

...here example (maybe you didn't mean this), if you want store "shots" what players have done.
On round end it will print in server console stored shot by index and will print to that player chat who is game.
Spoiler



uuhh... those old days.
Simple code what start count headshot [Help]
Bacardi is offline
sereky
Member
Join Date: Aug 2011
Old 02-10-2012 , 11:43   Re: How to use an event's client in another event? How to save each client?
Reply With Quote #6

Quote:
Originally Posted by Bacardi View Post
There is no sense to save player indexs...
you have purpose to use event weapon_fire for some reason ?

...
My source code is only an example.

This is another example from here:
http://forums.alliedmods.net/showthread.php?t=175819

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

new clip[MAXPLAYERS 1];
new 
client[MAXPLAYERS 1];

public 
OnPluginStart()
{
    
HookEvent("weapon_fire"OnWeaponFire);
    
HookEvent("bot_player_replace"bot_player_replace);
}

public 
Action:OnWeaponFire(Handle:event, const String:name[], bool:dontBroadcast)
{
    
client[?] = GetClientOfUserId(GetEventInt(event"userid"));
    new 
victim;

    new 
slot GetPlayerWeaponSlot(client0);
    
decl String:weaponname[32];
    
decl String:gun[64];
    
GetClientWeapon(clientweaponnamesizeof weaponname);
    
GetEdictClassname(slotgunsizeof(gun));
    if (
StrEqual(gunweaponnamefalse))
    {
        
victim GetPlayerWeaponSlot(client1);

        if (
victim != -1)
        {
            
clip[client] = GetEntProp(GetPlayerWeaponSlot(client1), Prop_Send"m_iClip1")
            
remove(client1);
            
CreateTimer(5.0givepistolclient);
            return;
        }
        return;
    }
}

public 
bot_player_replace(Handle:Spawn_Event, const String:Spawn_Name[], bool:Spawn_Broadcast)
{
    
bot GetClientOfUserId(GetEventInt(Spawn_Event"bot"));
    
player GetClientOfUserId(GetEventInt(Spawn_Event"player"));

    if (
client[?] == bot)
    {
        
giveweapon(player"weapon_pistol");
        
SetEntProp(GetPlayerWeaponSlot(player1), Prop_Send"m_iClip1"clip[client]);
    }
}

public 
Action:givepistol(Handle:timerany:client)
{
    
giveweapon(client"weapon_pistol");
    
SetEntProp(GetPlayerWeaponSlot(client1), Prop_Send"m_iClip1"clip[client]);
}

giveweapon(clientString:class[40])
{
    new 
ent CreateEntityByName(class);

    if (
ent != -1)
    {
        
DispatchSpawn(ent);
        
EquipPlayerWeapon(clientent);
    }
}

remove(clientslot)
{
    new 
ent GetPlayerWeaponSlot(clientslot);

    if (
ent != -1)
    {
        
RemovePlayerItem(clientent);
        
RemoveEdict(ent);
    }

I can save the clip of each client by clip[client] = ... , but I want to save each client. I don't know how to use client[?]. What sould be in the brackets?

You can read the description of this plugin in the link above. The new problem is that if a player take control a bot who's pistol removed temporarily and the timer isn't ended, this fix would give it back immediately to the player.

if (client[?] == bot) could compare them. This is why I want to save each client.

Last edited by sereky; 02-10-2012 at 11:47.
sereky is offline
sereky
Member
Join Date: Aug 2011
Old 04-29-2012 , 12:26   Re: How to use an event's client in another event? How to save each client?
Reply With Quote #7

What is the solution of this problem?
sereky is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 04-29-2012 , 13:07   Re: How to use an event's client in another event? How to save each client?
Reply With Quote #8

Code:
new bool:bMemory[ MAXPLAYERS+1 ] = { false, ... };

public Action:OnWeaponFire( Handle:hEvent, const String:strEventName[], bool:bDontBroadcast )
{
    new iClient = GetClientOfUserId( GetEventInt( hEvent, "userid" ) );
    
    if( !IsClientInGame( iClient ) )
        return Plugin_Continue;
        
    if( !IsFakeClient( iClient ) )
        return Plugin_Continue;
    
    bMemory[ iClient ] = true;
    
    return Plugin_Continue;
}

public Action:OnPlayerSpawn( Handle:hEvent, const String:strEventName[], bool:bDontBroadcast )
{
    new iClient = GetClientOfUserId( GetEventInt( hEvent, "userid" ) );
    
    if( !IsClientInGame( iClient ) )
        return Plugin_Continue;
    
    if( bMemory[ iClient ] )
    {
        // Do something;
        bMemory[ iClient ] = false;
    }
    
    return Plugin_Continue;
}
__________________
Leonardo is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 04-29-2012 , 13:24   Re: How to use an event's client in another event? How to save each client?
Reply With Quote #9

I think we'd have a better way to help if you explained what you needed and what you ultimately wanted to do with that client variable... you can use Trie to store a bunch of information (but use userId instead of clientId)
__________________
View my Plugins | Donate
TnTSCS is offline
sereky
Member
Join Date: Aug 2011
Old 05-05-2012 , 16:52   Re: How to use an event's client in another event? How to save each client?
Reply With Quote #10

Here is another example:

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

#pragma semicolon 1
new count[MAXPLAYERS+1];
new 
n_client;

public 
OnPluginStart()
{
    
HookEvent("heal_begin"heal_begin);
    
HookEvent("player_incapacitated"player_incapacitated);
}

public 
Action:player_incapacitated(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client n_client;
    
count[client]++;
}

public 
Action:heal_begin(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client;
    
client GetClientOfUserId(GetEventInt(event"userid"));
    if (
client == n_client)

    if (
count[client]>1)
    {
        
count[client]=0;
        
ForcePlayerSuicide(client);
    }

If a client incapacitated 2 times, then he begin healing, kill him. How to do this by storing clients?
sereky 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 15:39.


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