Simple Prefix System V 0.0.3

This bundle is marked as pending. It has not been reviewed by a staff member yet.
  • Like
Reactions: Vinz
Simple Prefix System V 0.0.3
Credits:
* Allknowledge aka iam20842 [port gui idea to jass]
* Templarfaker aka aple [original idea: [GUI] Simple Name Prefixes]


Why i need?

Because you want get better organization in your object editor (units only for now) adding custom prefix like: T1_archer, T1_knigth, T2_archer and go on and dont wanna see this prefix in-game

With this system you can add a prefix to the unit in object editor (for organization) and get this prefix removed in-game

Who it works?

EASY:
- First you need in your object editor a prefix over the unit name like this:
- In this case the separator is !, this mean, the prefix is KA or ME.

OnSOgqT.png


- Second you need to call the SPSSetRealName function to that unit, see SPSTest for an example

- Third enjoy!

- Four bug removed!

6vPosBD.png


EINSTHEIN:
- The system check if the unit got the real name previously (checking if in group PREFIX_OFF_GROUP)
- IF NOT the system look in the unit name the separator defined in SPSSetPrefix with GUI or SPSSetPrefix with Arg
- Thein IF find the separator will set to true hasFindPrefix (bug: prevent change the 2nd ocurrency)

- Thein create a new string without the string after the separator
- Thein change the unit name to the real name
- Thein add this unit to a group (bug: prevent unit with nameSEPARATOR that cause crash)



Triggers:

JASS:
globals

    string PREFIX_SEPARATOR = "!"
    group PREFIX_OFF_GROUP = CreateGroup()

endglobals

library SPS

    function SPSSetPrefixArg takes string prefix returns nothing
        set PREFIX_SEPARATOR = prefix
    endfunction

    function SPSSetPrefixGUI takes nothing returns nothing
        set PREFIX_SEPARATOR = udg_SPSPrefix
    endfunction

    function SPSGetRealName takes string unitName, integer separatorPosition returns string
        local integer stringLength = StringLength(unitName)
        local string prefix
        local string remainString
        local string newUnitName

        set prefix = SubString(unitName, 0, separatorPosition)
        set remainString = SubString(unitName, separatorPosition+2, stringLength)

        call BJDebugMsg("|cffffff00Prefix|r: " + prefix)
        call BJDebugMsg("|cffffff00Separator|r: " + PREFIX_SEPARATOR)
        call BJDebugMsg("|cffffff00Real Name|r: " + remainString)

        return remainString
    endfunction

    function SPSGetSeparatorPosition takes string unitName returns integer
        local integer i = 0
        local integer stringLength = StringLength(unitName)
        local boolean hasFindPrefix = false
        local string tempString
        local integer separatorPosition

        loop
            set tempString = SubString(unitName, i, i + 1)
            if (tempString == PREFIX_SEPARATOR) then
                if (hasFindPrefix == false) then
                    set separatorPosition = i
                    set hasFindPrefix = true
                endif
            endif
            set i = i + 1
            exitwhen i == stringLength
        endloop
        return separatorPosition
    endfunction

    function SPSSetRealName takes unit u returns nothing
        local string unitName
        local integer separatorPosition
        local string unitRealName

        if (IsUnitInGroup(u, PREFIX_OFF_GROUP) == true) then
            return
        else

            set unitName = GetUnitName(u)
            set separatorPosition = SPSGetSeparatorPosition(unitName)
            set unitRealName = SPSGetRealName(unitName, separatorPosition)

            call BlzSetUnitName(u, unitRealName)
            call GroupAddUnit(PREFIX_OFF_GROUP, u)
            set u = null
        endif
    endfunction

endlibrary

What is new?

0.0.2
-> GUI Friendly option
-> Rename new units, rename starting units
-> Set prefix function with or without parameters
-> Starting and Entering units get renamed inmediatly!, get examples in: SPSMapBegin and SPSUnitEnterMap triggers


0.0.3
-> GUI Now works better
-> Select unit, Mapbegin, UnitEnter options for the implementation of the systemd :D


PD: The other triggers are only instructions dont need to publish
Contents

Simple Prefix System V0.0.1 (Map)

Simple Prefix System V0.0.2 (Map)

Simple Prefix System V0.0.3 (Map)

Top