• Fixing a team to bodygroup script
    7 replies, posted
[B]Hi, I am getting the error with the following script:[/B] [ERROR] lua/autorun/server/bdygrp.lua:69: unexpected symbol near ')' 1. unknown - lua/autorun/server/bdygrp.lua:0 [B]AND[/B] [TheVingard|2|STEAM_0:1:95921723] Lua Error: [ERROR] lua/autorun/bdygrp.lua:75: ')' expected near 'then' 1. unknown - lua/autorun/bdygrp.lua:0 [B]Could you help? Thanks, Vin.[/B] [QUOTE] local TeamBodyGroups = { [ Security_Lieutenant ] = { model = "models/humans/guard.mdl"; -- string or table for random // Using my body-group string system; releasing soon in dev_base and dev_addon -- bodygroups = "1:2;2:1;3:5;"; // Using table method bodygroups = { [ 2 ] = 0; // Helmet [ 3 ] = 2; // Chest [ 4 ] = 1; // Holster [ 5 ] = 1; // Flashlight }; }; [ TEAM_SECURITY_CADET ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 0; }; }; [ TEAM_SECURITY_JUNIOR_OFFICER ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 1; }; }; [ TEAM_SECURITY_OFFICER ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 0; [ 4 ] = 1; [ 5 ] = 1; }; }; [ TEAM_SECURITY_SERGEANT ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 1; [ 4 ] = 1; [ 5 ] = 1; }; }; [ TEAM_SECURITY_CHIEF ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 2; [ 4 ] = 1; [ 5 ] = 1; }; }; hook.Add( "PlayerSetModel", "UpdatePlayerModel", function( _p ) ) local _team = _p:Team( ); local _data = TeamBodyGroups[ _team ]; if ( _data ) then local _model = _data.model; if ( _model ) then if ( isstring( _model ) ) then _p:SetModel( _model ); elseif ( istable( _model ) ) then _p:SetModel( table.Random( _model ) ); end end end end local _bodygroups = _data.bodygroups; if ( _bodygroups ) then if ( isstring( _bodygroups ) ) then -- using my system elseif ( istable( _bodygroups ) ) then for _id, _bodypart in pairs( _bodygroups ) do _p:SetBodygroup( _id, _bodypart ); end end end // Now, prevent the GM:PlayerSetModel or other hooks from running if we updated the model - we do this check twice because model needs to be set prior to setting body group, and we want to prevent this function from altering the model again... if ( _model ) then return true; end [/QUOTE]
Missed to close the hook.Add with a ) at the end after "end" [lua]local TeamBodyGroups = { [ Security_Lieutenant ] = { model = "models/humans/guard.mdl"; -- string or table for random // Using my body-group string system; releasing soon in dev_base and dev_addon -- bodygroups = "1:2;2:1;3:5;"; // Using table method bodygroups = { [ 2 ] = 0; // Helmet [ 3 ] = 2; // Chest [ 4 ] = 1; // Holster [ 5 ] = 1; // Flashlight }; }; [ TEAM_SECURITY_CADET ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 0; }; }; [ TEAM_SECURITY_JUNIOR_OFFICER ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 1; }; }; [ TEAM_SECURITY_OFFICER ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 0; [ 4 ] = 1; [ 5 ] = 1; }; }; [ TEAM_SECURITY_SERGEANT ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 1; [ 4 ] = 1; [ 5 ] = 1; }; }; [ TEAM_SECURITY_CHIEF ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 2; [ 4 ] = 1; [ 5 ] = 1; }; }; }; hook.Add( "PlayerSetModel", "UpdatePlayerModel", function( _p ) ) local _team = _p:Team( ); local _data = TeamBodyGroups[ _team ]; if ( _data ) then local _model = _data.model; if ( _model ) then if ( isstring( _model ) ) then _p:SetModel( _model ); elseif ( istable( _model ) ) then _p:SetModel( table.Random( _model ) ); end end end end) local _bodygroups = _data.bodygroups; if ( _bodygroups ) then if ( isstring( _bodygroups ) ) then -- using my system elseif ( istable( _bodygroups ) ) then for _id, _bodypart in pairs( _bodygroups ) do _p:SetBodygroup( _id, _bodypart ); end end end -- Now, prevent the GM:PlayerSetModel or other hooks from running if we updated the model - we do this check twice because model needs to be set prior to setting body group, and we want to prevent this function from altering the model again... if ( _model ) then return true; end [/lua]
[QUOTE=Darrell;50449849]Missed to close the hook.Add with a ) at the end after "end" [lua]local TeamBodyGroups = { [ Security_Lieutenant ] = { model = "models/humans/guard.mdl"; -- string or table for random // Using my body-group string system; releasing soon in dev_base and dev_addon -- bodygroups = "1:2;2:1;3:5;"; // Using table method bodygroups = { [ 2 ] = 0; // Helmet [ 3 ] = 2; // Chest [ 4 ] = 1; // Holster [ 5 ] = 1; // Flashlight }; }; [ TEAM_SECURITY_CADET ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 0; }; }; [ TEAM_SECURITY_JUNIOR_OFFICER ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 1; }; }; [ TEAM_SECURITY_OFFICER ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 0; [ 4 ] = 1; [ 5 ] = 1; }; }; [ TEAM_SECURITY_SERGEANT ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 1; [ 4 ] = 1; [ 5 ] = 1; }; }; [ TEAM_SECURITY_CHIEF ] = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 2; [ 4 ] = 1; [ 5 ] = 1; }; }; }; hook.Add( "PlayerSetModel", "UpdatePlayerModel", function( _p ) ) local _team = _p:Team( ); local _data = TeamBodyGroups[ _team ]; if ( _data ) then local _model = _data.model; if ( _model ) then if ( isstring( _model ) ) then _p:SetModel( _model ); elseif ( istable( _model ) ) then _p:SetModel( table.Random( _model ) ); end end end end) local _bodygroups = _data.bodygroups; if ( _bodygroups ) then if ( isstring( _bodygroups ) ) then -- using my system elseif ( istable( _bodygroups ) ) then for _id, _bodypart in pairs( _bodygroups ) do _p:SetBodygroup( _id, _bodypart ); end end end -- Now, prevent the GM:PlayerSetModel or other hooks from running if we updated the model - we do this check twice because model needs to be set prior to setting body group, and we want to prevent this function from altering the model again... if ( _model ) then return true; end [/lua][/QUOTE] Thanks for the reply. But I now get this error: [ERROR] lua/autorun/server/bdygrp.lua:80: unexpected symbol near ')' 1. unknown - lua/autorun/server/bdygrp.lua:0
Yuep, sorry. My bad. Wasn't all awake. This should work. Fixed up the whole script. [lua] local TeamBodyGroups = { Security_Lieutenant = { model = "models/humans/guard.mdl"; -- string or table for random -- Using my body-group string system; releasing soon in dev_base and dev_addon -- bodygroups = "1:2;2:1;3:5;"; -- Using table method bodygroups = { [ 2 ] = 0; -- Helmet [ 3 ] = 2; -- Chest [ 4 ] = 1; -- Holster [ 5 ] = 1; -- Flashlight } }, TEAM_SECURITY_CADET = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 0; } }, TEAM_SECURITY_JUNIOR_OFFICER = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 1; } }, TEAM_SECURITY_OFFICER = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 0; [ 4 ] = 1; [ 5 ] = 1; } }, TEAM_SECURITY_SERGEANT = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 1; [ 4 ] = 1; [ 5 ] = 1; } }, TEAM_SECURITY_CHIEF = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 2; [ 4 ] = 1; [ 5 ] = 1; } }, }; hook.Add( "PlayerSetModel", "UpdatePlayerModel", function( _p ) local _team = _p:Team( ); local _data = TeamBodyGroups[ _team ]; if ( _data ) then local _model = _data.model; if ( _model ) then if ( isstring( _model ) ) then _p:SetModel( _model ); elseif ( istable( _model ) ) then _p:SetModel( table.Random( _model ) ); end end end end) local _bodygroups = _data.bodygroups; if ( _bodygroups ) then if ( isstring( _bodygroups ) ) then -- using my system elseif ( istable( _bodygroups ) ) then for _id, _bodypart in pairs( _bodygroups ) do _p:SetBodygroup( _id, _bodypart ); end end end -- Now, prevent the GM:PlayerSetModel or other hooks from running if we updated the model - we do this check twice because model needs to be set prior to setting body group, and we want to prevent this function from altering the model again... if ( _model ) then return true; end [/lua]
[QUOTE=Darrell;50450762]Yuep, sorry. My bad. Wasn't all awake. This should work. Fixed up the whole script. [lua] local TeamBodyGroups = { Security_Lieutenant = { model = "models/humans/guard.mdl"; -- string or table for random -- Using my body-group string system; releasing soon in dev_base and dev_addon -- bodygroups = "1:2;2:1;3:5;"; -- Using table method bodygroups = { [ 2 ] = 0; -- Helmet [ 3 ] = 2; -- Chest [ 4 ] = 1; -- Holster [ 5 ] = 1; -- Flashlight } }, TEAM_SECURITY_CADET = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 0; } }, TEAM_SECURITY_JUNIOR_OFFICER = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 1; } }, TEAM_SECURITY_OFFICER = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 0; [ 4 ] = 1; [ 5 ] = 1; } }, TEAM_SECURITY_SERGEANT = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 1; [ 4 ] = 1; [ 5 ] = 1; } }, TEAM_SECURITY_CHIEF = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 2; [ 4 ] = 1; [ 5 ] = 1; } }, }; hook.Add( "PlayerSetModel", "UpdatePlayerModel", function( _p ) local _team = _p:Team( ); local _data = TeamBodyGroups[ _team ]; if ( _data ) then local _model = _data.model; if ( _model ) then if ( isstring( _model ) ) then _p:SetModel( _model ); elseif ( istable( _model ) ) then _p:SetModel( table.Random( _model ) ); end end end end) local _bodygroups = _data.bodygroups; if ( _bodygroups ) then if ( isstring( _bodygroups ) ) then -- using my system elseif ( istable( _bodygroups ) ) then for _id, _bodypart in pairs( _bodygroups ) do _p:SetBodygroup( _id, _bodypart ); end end end -- Now, prevent the GM:PlayerSetModel or other hooks from running if we updated the model - we do this check twice because model needs to be set prior to setting body group, and we want to prevent this function from altering the model again... if ( _model ) then return true; end [/lua][/QUOTE] Hi, I still get this error: [ERROR] lua/autorun/server/bdygrp.lua:90: attempt to index global '_data' (a nil value) 1. unknown - lua/autorun/server/bdygrp.lua:90 [B]and[/B] [ERROR] lua/autorun/bdygrp.lua:75: ')' expected near 'then' 1. unknown - lua/autorun/bdygrp.lua:0
[lua] local TeamBodyGroups = { Security_Lieutenant = { model = "models/humans/guard.mdl"; -- string or table for random -- Using my body-group string system; releasing soon in dev_base and dev_addon -- bodygroups = "1:2;2:1;3:5;"; -- Using table method bodygroups = { [ 2 ] = 0; -- Helmet [ 3 ] = 2; -- Chest [ 4 ] = 1; -- Holster [ 5 ] = 1; -- Flashlight } }, TEAM_SECURITY_CADET = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 0; } }, TEAM_SECURITY_JUNIOR_OFFICER = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 1; } }, TEAM_SECURITY_OFFICER = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 0; [ 4 ] = 1; [ 5 ] = 1; } }, TEAM_SECURITY_SERGEANT = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 1; [ 4 ] = 1; [ 5 ] = 1; } }, TEAM_SECURITY_CHIEF = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 2; [ 4 ] = 1; [ 5 ] = 1; } }, }; hook.Add( "PlayerSetModel", "UpdatePlayerModel", function( _p ) local _team = _p:Team( ); local _data = TeamBodyGroups[ _team ]; if ( _data ) then local _model = _data.model; if ( _model ) then if ( isstring( _model ) ) then _p:SetModel( _model ); elseif ( istable( _model ) ) then _p:SetModel( table.Random( _model ) ); end end end local _bodygroups = _data.bodygroups; if ( _bodygroups ) then if ( isstring( _bodygroups ) ) then -- using my system elseif ( istable( _bodygroups ) ) then for _id, _bodypart in pairs( _bodygroups ) do _p:SetBodygroup( _id, _bodypart ); end end end -- Now, prevent the GM:PlayerSetModel or other hooks from running if we updated the model - we do this check twice because model needs to be set prior to setting body group, and we want to prevent this function from altering the model again... if ( _model ) then return true; end end) [/lua]
[QUOTE=Darrell;50453993][lua] local TeamBodyGroups = { Security_Lieutenant = { model = "models/humans/guard.mdl"; -- string or table for random -- Using my body-group string system; releasing soon in dev_base and dev_addon -- bodygroups = "1:2;2:1;3:5;"; -- Using table method bodygroups = { [ 2 ] = 0; -- Helmet [ 3 ] = 2; -- Chest [ 4 ] = 1; -- Holster [ 5 ] = 1; -- Flashlight } }, TEAM_SECURITY_CADET = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 0; } }, TEAM_SECURITY_JUNIOR_OFFICER = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 1; [ 3 ] = 0; [ 4 ] = 0; [ 5 ] = 1; } }, TEAM_SECURITY_OFFICER = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 0; [ 4 ] = 1; [ 5 ] = 1; } }, TEAM_SECURITY_SERGEANT = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 1; [ 4 ] = 1; [ 5 ] = 1; } }, TEAM_SECURITY_CHIEF = { model = "models/humans/guard.mdl"; bodygroups = { [ 2 ] = 0; [ 3 ] = 2; [ 4 ] = 1; [ 5 ] = 1; } }, }; hook.Add( "PlayerSetModel", "UpdatePlayerModel", function( _p ) local _team = _p:Team( ); local _data = TeamBodyGroups[ _team ]; if ( _data ) then local _model = _data.model; if ( _model ) then if ( isstring( _model ) ) then _p:SetModel( _model ); elseif ( istable( _model ) ) then _p:SetModel( table.Random( _model ) ); end end end local _bodygroups = _data.bodygroups; if ( _bodygroups ) then if ( isstring( _bodygroups ) ) then -- using my system elseif ( istable( _bodygroups ) ) then for _id, _bodypart in pairs( _bodygroups ) do _p:SetBodygroup( _id, _bodypart ); end end end -- Now, prevent the GM:PlayerSetModel or other hooks from running if we updated the model - we do this check twice because model needs to be set prior to setting body group, and we want to prevent this function from altering the model again... if ( _model ) then return true; end end) [/lua][/QUOTE] Hi again, I now get only this error: [ERROR] lua/autorun/bdygrp.lua:75: ')' expected near 'then' 1. unknown - lua/autorun/bdygrp.lua:0 and it crashes clients on join with engine error: GetLuaTable != TABLE! Type is: 0 Thanks again.
[QUOTE=TheVingard;50454008]Hi again, I now get only this error: [ERROR] lua/autorun/bdygrp.lua:75: ')' expected near 'then' 1. unknown - lua/autorun/bdygrp.lua:0 and it crashes clients on join with engine error: GetLuaTable != TABLE! Type is: 0 Thanks again.[/QUOTE] Can't you try to fix it by yourself and looking at the error instead of saying: Hey it errors, somebody fix it for me beacouse I can't and I don't know how to read an error.
Sorry, you need to Log In to post a reply to this thread.