Muche Posted December 29, 2015 Share Posted December 29, 2015 Hello.I'm working on a patch for Moderator Commands mod that would display moderators on the player status screen (by showing a badge, similar to admin's badge).For each player I am setting up net_string based on that player's userid.I discovered that AddPlayerPostInit gets executed also for Global Positions' globalposition_classified, as it has Player tag. In other mods I've seen it is usually distinguished by checking for existence of a specific component.As globalposition_classified has userid field, which is net_string, I settled for checking its type. Is this the correct approach?Thanks. function updateRank(inst) local rank = get_rank(inst.userid or "") local rankUI = get_pretty_name(rank) inst.net_rank:set(rank) inst.net_rankUI:set(rankUI)endAddPlayerPostInit(function(inst) -- check for Global Positions' globalposition_classified if type(inst.userid) == "string" then GLOBAL.assert(inst.net_rank == nil and inst.net_rankUI == nil, "Rank already found in " .. tostring(inst) .. ", caused most probably by incompatibility between mods.") inst.net_rank = GLOBAL.net_string(inst.GUID, "rank") inst.net_rankUI = GLOBAL.net_string(inst.GUID, "rankUI") if GLOBAL.TheWorld.ismastersim then -- userid is not filled yet, set rank to user in the interim local rank = "user" local rankUI = get_pretty_name(rank) inst.net_rank:set(rank) inst.net_rankUI:set(rankUI) inst:DoTaskInTime(0.1, updateRank) end endend) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now