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

[EXAMPLE] SHVector and player tracking


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
API
Veteran Member
Join Date: May 2006
Old 05-14-2007 , 00:09   [EXAMPLE] SHVector and player tracking
Reply With Quote #1

This is an example of easy player tracking with SHVector.
Code:
#pragma semicolon 1

#include <sourcemod>
#include <shvector>

// Vector Handles
new Handle:vecPlayers;

public Plugin:myinfo = 
{
    name = "Example Player Tracking",
    author = "PimpinJuice",
    description = "An example of easy player tracking using SHVector.",
    version = "1.0.0",
    url = "http://pimpinjuice.net/"
};

public OnPluginStart()
{
    vecPlayers=SHVectorCreate(TYPE_CELL);
    HookEvent("player_death",Event_PlayerDeath);
}

public GetClientVectorPosition(client)
{
    for(new x=0;x<SHVectorSize_Cell(vecPlayers);x++)
    {
        new Handle:ply=SHVectorAt_Cell(vecPlayers,x);
        new curClient=SHVectorAt_Cell(ply,0);
        if(client==curClient)
            return x;
    }
    return -1;
}

public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
    // This will give the killer 25 xp and if they get to 100 xp they level and their XP goes back to 0
    if(GetEventInt(event,"userid")!=GetEventInt(event,"attacker")&&GetEventInt(event,"attacker")>0)
    {
        new attackerIndex=GetClientOfUserId(GetEventInt(event,"attacker"));
        new vecPos=GetClientVectorPosition(attackerIndex);
        if(vecPos!=-1)
        {
            new Handle:clientVecData=SHVectorAt_Cell(vecPlayers,vecPos);
            new newXP=SHVectorAt_Cell(clientVecData,1)+25;
            SHVectorSetAt_Cell(clientVecData,1,newXP);
            if(newXP>=100)
            {
                SHVectorSetAt_Cell(clientVecData,1,0);
                new newLevel=SHVectorAt_Cell(clientVecData,2)+1;
                SHVectorSetAt_Cell(clientVecData,2,newLevel);
            }
            SHVectorSetAt_Cell(vecPlayers,vecPos,clientVecData);
        }
    }
}

public OnClientPutInServer(client)
{
    if(client>0)
    {
        new Handle:newPlayer=SHVectorCreate(TYPE_CELL);
        SHVectorInsert_Cell(newPlayer,ITER_BACK,client); // The first thing is client index
        SHVectorInsert_Cell(newPlayer,ITER_BACK,0); // Place-holder for XP points
        SHVectorInsert_Cell(newPlayer,ITER_BACK,0); // Place-holder for current level
        SHVectorInsert_Cell(vecPlayers,ITER_BACK,newPlayer); // Put our new player at the end of the vecPlayers vector
    }
}

public OnPluginEnd()
{
    for(new x=0;x<SHVectorSize_Cell(vecPlayers);x++)
        SHVectorFree_Cell(SHVectorAt_Cell(vecPlayers,x));
    SHVectorFree_Cell(vecPlayers);
}
Basically, it is an example of an XP system for a plugin.

Hope you guys get good use out of it.
__________________
API is offline
Send a message via AIM to API
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 12:28.


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