- Joined
- Dec 12, 2008
- Messages
- 7,385
I explained what this is for in the documentation below.
Feel free to comment.
JASS:
/***********************************************
*
* FileIOPlayerNameSafety
* v1.1.0.0
* By Magtheridon96
*
* - This plugin evaluates player names to ensure
* that FileIO will not face any problems while
* reading from files. A names that starts with
* a single space can break the entire system,
* so this thing removes those unneeded spaces.
*
* This plugin works with:
* -----------------------
*
* FileIO by Nestharus
* - hiveworkshop.com/forums/spells-569/file-i-o-2-0-0-1-a-217403/
*
* API:
* ----
*
* function EvaluatePlayerNamesForFileIOSafety takes nothing returns nothing
* - This will run one player name evaluation. Player names will be
* changed accordingly.
*
***********************************************/
library FileIOPlayerNameSafety
globals
/*
* You may need periodic name evaluation if
* your map allows players to change their names
* to anything they want. If you do not feel like
* calling the main API function after every name
* change, you can set this to true and configure
* the period to your liking.
*/
private constant boolean PERIODIC_EVALUATION = false
/*
* This is the interval in which evaluations
* for player names are done in a map. 1 second
* is a nice value.
*/
private constant real PERIOD = 1
endglobals
private module Init
private static method onInit takes nothing returns nothing
call evaluateNames()
static if PERIODIC_EVALUATION then
call TimerStart(CreateTimer(), PERIOD, true, function thistype.evaluateNames)
endif
endmethod
endmodule
private struct NameSafety extends array
static method evaluateNames takes nothing returns nothing
local integer index = 15
local integer position = 0
local integer length = 0
local string name
local player p
loop
set p = Player(index)
set name = GetPlayerName(p)
set length = StringLength(name)
loop
exitwhen position == length or SubString(name, position, position + 1) != " "
set position = position + 1
endloop
if position != 0 then
call SetPlayerName(p, SubString(name, position, length))
set position = 0
endif
exitwhen index == 0
set index = index - 1
endloop
set p = null
endmethod
implement Init
endstruct
function EvaluatePlayerNamesForFileIOSafety takes nothing returns nothing
call NameSafety.evaluateNames()
endfunction
endlibrary
Feel free to comment.
Last edited: