OnCharVarChanged

From Nutscript Developer Wiki
   GM:OnCharVarChanged(char, varName, oldVar, newVar)

Description[edit]

This function is called when character's networking variable is just changed. The variables means important character's variables which is money, attributes, desc, name... This can be used to tracking the change of the player's characters.

Arguments[edit]

  • Character char
  • String varName
  • Variable oldVar
  • Variable newVar

Return Values[edit]

return none

Examples[edit]

Example for a rank system that changes model based on character name:

   local rankTable = {
       {"Rank1" -- rank name, CLASS_RANK1 -- class, "models/coolmodel.mdl" -- model, 2 --skin},
       {"Rank2", CLASS_RANK2, "models/coolmodel2.mdl", 1}
   }
   function SCHEMA:OnCharVarChanged(character, var, oldValue, value)
       if var != "name" then return end -- make sure that the changed variable is a name and nothing else. if its not a name it ends
       for k, v in ipairs(rankTable) do
           if (!string.find(oldValue, "[%D+]"..v[1].."[%D+]") and string.find(value, "[%D+]"..v[1].."[%D+]")) then -- check if we have the right rank (totally not ripped from helix hl2rp :P)
               character:setClass(v[2]) -- set class!
               character:setSkin(v[4] or 0) -- set skin to given number or to 0!
                   if v[3] != nil then
                       character:setModel(v[3]) -- set model if we have one!
                   end
               break -- we break it there is no need to go through the rest as we have already found the correct rank!
           end
       end
   end