Changing Class from console

Discussion in 'Coding' started by Misfire, Nov 14, 2015.

  1. Misfire

    Misfire Always Lost

    Messages:
    311
    Likes Received:
    44
    Trophy Points:
    0
    I'm looking for information that will help me complete a sourcemod plugin. Any one have information or sample code that would let me change a player class (and maybe weapon loadout) ? Plenty of examples out there for TF2, not so much for Empires. Thnx
     
  2. 101010

    101010 Member

    Messages:
    996
    Likes Received:
    2
    Trophy Points:
    0
    Most tf2 plugins would use the tf2 stocks in the include.
    Example
    "tf2_player
    stock const String:TF2_TeamName[TFTeam][]
    stock const String:TF2_ClassName[TFClassType][]
    stock const TF2_ClassHealth[TFClassType]
    stock const Float:TF2_ClassSpeed[TFClassType]
    const String:TF2_GetClassName(TFClassType:class)
    TF2_GetClassHealth(TFClassType:class)
    Float:TF2_GetClassSpeed(TFClassType:class)
    stock TF2_GetNumHealers(client)
    stock Float:TF2_GetPlayerSpeed(client)
    stock TF2_GetPlayerMaxHealth(client)
    bool:TF2_Is<condition>(pcond)
    bool:TF2_IsPlayer<condition>(client)
    stock TF2_GetPlayerConditionLowBits(client)
    stock TF2_GetPlayerConditionHighBits(client"

    You would need to use Emp_stocks in your empires include
    Example

    "/**
    * Retrieves a player's class
    *
    * @param client Client Index
    * @return Player class (0 is scout, 1 is rifleman, 2 is gren, 3 is engy, 5 is spec)
    */
    stock GetPlayerClassNum(client)
    {
    new maxents = GetMaxEntities();
    decl String:classname[64];
    new ent;
    for(new i = 0; i <= maxents; i++){
    if(IsValidEntity(i)){
    GetEntityNetClass(i, classname, sizeof(classname));
    if(StrEqual(classname, "CPlayerResource")){
    ent = i;
    break;
    }
    }
    }
    new offset = FindSendPropOffs("CPlayerResource", "m_iClass");
    new out = GetEntData(ent, offset + (client*4), 4);
    return out;
    }

    /**
    * Retrieves a player's class
    *
    * @param client Client Index
    * @param buffer Buffer to hold the class name
    * @param size Len of the buffer
    * @return Player class index
    */
    stock GetPlayerClassName(client, String:buffer[], size)
    {
    new maxents = GetMaxEntities();
    decl String:classname[64];
    new ent;
    for(new i = 0; i <= maxents; i++){
    if(IsValidEntity(i)){
    GetEntityNetClass(i, classname, sizeof(classname));
    if(StrEqual(classname, "CPlayerResource")){
    ent = i;
    break;
    }
    }
    }
    new offset = FindSendPropOffs("CPlayerResource", "m_iClass");
    new out = GetEntData(ent, offset + (client*4), 4);
    new Handle:ClassNames = CreateTrie();
    SetTrieString(ClassNames, "0", "Scout", true);
    SetTrieString(ClassNames, "1", "Rifleman", true);
    SetTrieString(ClassNames, "2", "Grenadier", true);
    SetTrieString(ClassNames, "3", "Engineer", true);
    SetTrieString(ClassNames, "4", "Unknown", true);
    SetTrieString(ClassNames, "5", "None", true);
    decl String:class[64], String:classname2[64];
    IntToString(out, class ,sizeof(class));
    GetTrieString(ClassNames, class, classname2, sizeof(classname2));
    strcopy(buffer, size, classname2);
    return out;
    }"
     

Share This Page