Thread: SetTeamScore
View Single Post
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-15-2011 , 19:10   Re: SetTeamScore
Reply With Quote #4

It seems Sourcemod doesn't mark the property as changed, bleh.
Use my stocks:

PHP Code:
/*
* Changes a team's score.
* Don't use this before OnMapStart().
*
* @param index            Team Index.
* @param score            Score value.
* @return                True on success, false otherwise
*/
stock bool:Team_SetScore(indexscore)
{
    new 
edict Team_GetEdict(index);
    
    if (
edict == -1) {
        return 
false;
    }

    
SetEntProp(edictProp_Send"m_iScore"score);
    
ChangeEdictState(edictGetEntSendPropOffs(edict"m_iScore"));
    
    return 
true;
}

/*
* Gets a team's edict (team_manager) Team Index.
* Don't call this before OnMapStart()
*
* @param edict            Edict
* @return                Team Index
*/
stock Team_EdictGetNum(edict)
{
    return 
GetEntProp(edictProp_Send"m_iTeamNum");
}

/*
* Gets a team's edict (team_manager)
* Don't call this before OnMapStart()
*
* @param index            Team Index.
* @return                Team edict or -1 if not found
*/
stock Team_GetEdict(index)
{
    new 
maxEntities GetMaxEntities();
    for (new 
entity=MaxClients+1entity maxEntitiesentity++) {
        
        if (!
IsValidEntity(entity)) {
            continue;
        }
        
        if (!
Entity_CheckClassName(entity"team_manager"true)) {
            continue;
        }
        
        if (
Team_EdictGetNum(entity) == index) {
            return 
entity;
        }
    }
    
    return -
1;
}

/*
 * Checks if an entity matches a specific entity class.
 *
 * @param entity        Entity Index.
 * @param class            Classname String.
 * @return                True if the classname matches, false otherwise.
 */
stock bool:Entity_CheckClassName(entity, const String:className[], partialMatch=false)
{
    
decl String:entity_className[64];
    
GetEdictClassname(entityentity_classNamesizeof(entity_className));

    if (
partialMatch) {
        return (
StrContains(entity_classNameclassName) != -1);
    }
    
    return 
StrEqual(entity_classNameclassName);

__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 01-16-2011 at 20:39. Reason: Updated stocks
berni is offline