• Help with table not being recieved
    2 replies, posted
Hi. Currently working on a script that means certain jobs can't take fall damage as you can see, except when I run this I still take damage. Any help would be much appreciated function NoFallDAM(ply, speed) local RMTNames = { TEAM_RMTCOMMANDER, TEAM_RMTEXECUTIVEOFFICER, TEAM_RMTMAJOR, TEAM_RMTCRUSADER, TEAM_RMTLIEUTENANT, TEAM_RMTSERGEANT, TEAM_RMTTROOPER, }     if (ply:Team() == (RMTNames)) then         return 0     end end hook.Add("GetFallDamage", "nofall", NoFallDAM)
I don't code for gmod anymore, but I know Lua so maybe I can help. It looks like you're trying to compare a single team (ply:Team()) against an entire table of teams (RMTNames). These of course will never be equal, you need to check if ply:Team() is one of the teams in that table. With Lua, it is easier to use the teams as keys, instead of as values how you do currently. Example of teams as keys: local RMTNames = { } RMTNames.TEAM_RMTCOMMANDER = true RMTNAMES.TEAM_RMTEXECUTIVEOFFICER = true etc etc for all the different teams. then all you need to do to check is if (RMTNames[ply:Team()]) then return 0 end
The way you've done your table didn't seem to work function NoFallDAM(ply, speed) local RMTNames = { }  RMTNames.TEAM_RMTCOMMANDER = true RMTNames.TEAM_RMTEXECUTIVEOFFICER = true RMTNames.TEAM_RMTMAJOR = true RMTNames.TEAM_RMTCRUSADER = true RMTNames.TEAM_RMTLIEUTENANT = true RMTNames.TEAM_RMTSERGEANT = true RMTNames.TEAM_RMTTROOPER = true       if (RMTNames[ply:Team()]) then          return 0 end end hook.Add("GetFallDamage", "nofall", NoFallDAM) local RMTNames = { [TEAM_RMTCOMMANDER] = true, [TEAM_RMTEXECUTIVEOFFICER] = true. [TEAM_RMTMAJOR] = true, [TEAM_RMTCRUSADER] = true, [TEAM_RMTLIEUTENANT] = true, [TEAM_RMTSERGEANT] = true, [TEAM_RMTTROOPER] = true, } Now it works, thanks for your help with the check and setting my table values to true though
Sorry, you need to Log In to post a reply to this thread.