• Print

Author Topic: setting up classes to be restricted to certain people in nutscript  (Read 5721 times)

0 Members and 1 Guest are viewing this topic.

Offline Capin

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Code: Lua
  1. SCHEMA.name = "The Institute Warhammer40K RP"
  2. SCHEMA.desc = "A Semi-Serious Warhammer40K Server."
  3. SCHEMA.author = "Capin"
  4.  
  5. nut.currency.set("$","Credit","Credits")
  6.  
  7. nut.util.includeDir("hooks")
  8. nut.util.includeDir("config")
  9.  
  10. function SCHEMA:isCombineFaction(faction)
  11.         return faction == FACTION_SONS_OF_DORN or faction == FACTION_OW
  12. end
  13.  
  14. do
  15.         local playerMeta = FindMetaTable("Player")
  16.  
  17.         function playerMeta:isCombine()
  18.                 return SCHEMA:isCombineFaction(self:Team())
  19.         end
  20.  
  21.         function playerMeta:getCombineRank()
  22.                 local name = self:Name()
  23.  
  24.                 for k, v in ipairs(SCHEMA.techmarineRanks) do
  25.                         local rank = string.PatternSafe(v)
  26.  
  27.                         if (name:find("[%D+]"..rank.."[%D+]")) then
  28.                                 return v
  29.                         end
  30.                 end
  31.         end
  32.        
  33.                 function playerMeta:isCombineRank(rank)
  34.                 if (type(rank) == "table") then
  35.                         local name = self:Name()
  36.  
  37.                         for k, v in ipairs(rank) do
  38.                                 local rank = string.PatternSafe(v)
  39.  
  40.                                 if (name:find("[%D+]"..rank.."[%D+]")) then
  41.                                         return v
  42.                                 end                            
  43.                         end
  44.  
  45.                         return false
  46.                 else
  47.                         return self:getCombineRank() == rank
  48.                 end
  49.         end
  50.        
  51.         function playerMeta:getRank()
  52.                 for k, v in ipairs(team.GetPlayers(FACTION_SONS_OF_DORN)) do
  53.                         local techmarineRanks = string.Explode(",", nut.config.get("Techmarine"):gsub("%s", ""))
  54.                         local name = string.PatternSafe(v:Name())
  55.  
  56.                         for k, v in ipairs(techmarineRanks) do
  57.                                 if (name:find(v)) then
  58.                                         return CLASS_TECHMARINE
  59.                                 end
  60.                         end
  61.                         end
  62.                         end
  63.                         end
I modified this from the HL2RP schema for nutscript to try and work for my schema. Whenever I try to switch to the class when I have my name modified to "Techmarine, Test" and try /beclass Techmarine it says failed to become techmarine so I'm really not sure what I did wrong. Also this error pops up and I'm not sure how to fix it.
« Last Edit: June 02, 2016, 08:26:19 pm by JamminR »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: setting up classes to be restricted to certain people in nutscript
« Reply #1 on: June 02, 2016, 08:29:46 pm »
Please, use code=lua tags when posting code. It wraps your code in a nice box, and gives line numbers, which are important for the next part.
Though I'm likely no help with this code, providing the exact error your getting, all lines of it, will help anyone trying to help you.
It will also specify line numbers near the error.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Capin

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: setting up classes to be restricted to certain people in nutscript
« Reply #2 on: June 05, 2016, 09:09:40 am »
Code: Lua
  1. CLASS.name = "Techmarine"
  2. CLASS.faction = FACTION_SONS_OF_DORN
  3. CLASS.color = Color(180, 180, 180)
  4. CLASS.loadout = {
  5. }
  6.  
  7. CLASS_TECHMARINE = CLASS.index
  8.  
  9. if (SERVER) then
  10.         -- Hook the 'charname' variable to change the class of a playing if the character's name
  11.         -- contains '.RCT' inside.
  12.         nut.char.HookVar("charname", "Techmarine", function(character)
  13.                 local client = character.player
  14.  
  15.                 if (IsValid(client) and client:Team() == FACTION_SONS_OF_DORN and string.find(character:GetVar("charname"), "Techmarine")) then
  16.                         client:SetCharClass(CLASS_TECHMARINE)
  17.                 end
  18.         end)
  19. end

I've decided to try and use this instead but it isn't switching me to the class. Anyone have any ideas how to get it to work?
« Last Edit: June 05, 2016, 09:12:42 am by Capin »

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: setting up classes to be restricted to certain people in nutscript
« Reply #3 on: June 06, 2016, 02:36:06 am »
I don't see any syntax errors in your code. Unless someone uses Nutscript it's unlikely they'll be able to help you. I think it would be a good idea to post on Facepunch asking for help with this, as you're more likely to get help there simply due to the larger userbase. You might even get a reply from Chessnut himself.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

  • Print