All pastes #935935 Raw Edit

Someone

public lua v1 · immutable
·published 2008-03-10 00:38 UTC
rendered paste body
// @name SimpleRP API// @author: Motive// @website: www.roleplayershub.com// @email: trelorn@gmail.com// ---------------------------------// Needed vars:// Array Size 12 boolean udg_IsAdmin Default: False// Single string udg_ShortMapName Default: "SimpleRP API"// Single string udg_prefix Default: "@"globals    string              udg_ShortMapName    = "SimpleRP API"    string              udg_prefix          = "@"    boolean array       udg_IsAdmin             endglobals// void RP_SendErrorMessageToPlayer(player p, string message)// Sends an error message to a player.function RP_SendErrorMessageToPlayer takes player p, string message returns nothing    local string send = "|cff0000" + message    call DisplayTextToPlayer(p, 0, 0, send)    endfunction// bool RP_IsAdmin(player p)// Returns true/false, depending on whether or not a player is an adminfunction RP_IsAdmin takes player p returns boolean    local integer id = GetPlayerId(p)    return udg_IsAdmin[id]endfunction// int RP_FindString(string haystack, string needle)// Returns the position of the needle in the haystack.function RP_FindString takes string haystack, string needle returns integer    local integer hlength = StringLength(haystack)    local integer nlength = StringLength(needle)    local integer curpos = 0    local integer result = -2        local string temp = ""    loop        set temp = SubString(haystack, curpos, curpos + nlength)        if temp == needle then            set result = curpos        else            if curpos == hlength then                set result = -1            endif        endif        set curpos = curpos + 1        exitwhen result != -2     endloop        return resultendfunction// void RP_HandleUnitCommands(player plr, string message)// Handles commands dealing with the "unit" command typefunction RP_HandleUnitCommands takes player plr, string message returns nothing    endfunction// void RP_HandleChatMessage(player plr, string message)// Handles every chat message input by the player.function RP_HandleChatMessage takes player plr, string message returns nothing    local integer spaceLocation1    local string commandtype    local string firstChar = SubString(message, 1, 1)        // Check for command prefix: @    if firstChar != udg_prefix then        return    endif    // Get the space after the command prefix: @unit" " kill    // if we're missing a space, then it's not a valid command.        set spaceLocation1 = RP_FindString(message, " ")    if spaceLocation1 == -2 then        call RP_SendErrorMessageToPlayer(plr, "Invalid command.")        return    endif        // Get the command type. Ex: @"unit" kill    // Terminate execution on calling the specific handler    set commandtype = SubString(message, 2, spaceLocation1 - 1)        if commandtype == "unit" then        call RP_HandleUnitCommands(plr, SubString(message, spaceLocation1 +1, StringLength(message)))        return    endif    // We're lacking a valid command type :(       call RP_SendErrorMessageToPlayer(plr, udg_ShortMapName + " has no \"" + commandtype + "\" command type.")endfunction