• Spawning with a random PlayerModel
    2 replies, posted
How would I go about using this table to make it so players spawn with a random playermodels? Any help appreciated greatly [QUOTE]modeltableRebels = { ["models/player/Group03/male_07.mdl"] = true, ["models/player/Group03m/male_09.mdl"] = true, ["models/player/odessa.mdl"] = true, ["models/player/Group01/male_05.mdl"] = true, }[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSpawn]GM/PlayerSpawn[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/table/Random]table.Random[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetModel]Entity:SetModel[/url] [editline]5th March 2016[/editline] Note if you used table.Random, it wouldn't return a random table key, it would return a random table value, so you'd have to do [CODE] modeltableRebels = { "models/player/Group03/male_07.mdl", "models/player/Group03m/male_09.mdl", "models/player/odessa.mdl", "models/player/Group01/male_05.mdl", } [/CODE] Instead of the table you're using for that to work, or you could swap the table's keys and the values using a simple script or just use a different function [editline]5th March 2016[/editline] E.G. [CODE] modeltableRebels = { "models/player/Group03/male_07.mdl", "models/player/Group03m/male_09.mdl", "models/player/odessa.mdl", "models/player/Group01/male_05.mdl", } hook.Add( 'PlayerSpawn', 'DoRandomModel', function( ply ) ply:SetModel( table.Random( modeltableRebels ) ) end ) [/CODE] ^ Untested [editline]6th March 2016[/editline] Note you should use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerInitialSpawn]GM/PlayerInitialSpawn[/url] if you only want their model to change when they first spawn on the server, not whenever they respawn.
[QUOTE=MPan1;49874892][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSpawn]GM/PlayerSpawn[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/table/Random]table.Random[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetModel]Entity:SetModel[/url] [editline]5th March 2016[/editline] Note if you used table.Random, it wouldn't return a random table key, it would return a random table value, so you'd have to do [CODE] modeltableRebels = { "models/player/Group03/male_07.mdl", "models/player/Group03m/male_09.mdl", "models/player/odessa.mdl", "models/player/Group01/male_05.mdl", } [/CODE] Instead of the table you're using for that to work [editline]5th March 2016[/editline] E.G. [CODE] modeltableRebels = { "models/player/Group03/male_07.mdl", "models/player/Group03m/male_09.mdl", "models/player/odessa.mdl", "models/player/Group01/male_05.mdl", } hook.Add( 'PlayerSpawn', 'DoRandomModel', function( ply ) ply:SetModel( table.Random( modeltableRebels ) ) end ) [/CODE] ^ Untested [editline]6th March 2016[/editline] Note you should use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerInitialSpawn]GM/PlayerInitialSpawn[/url] if you only want their model to change when they first spawn on the server, not whenever they respawn.[/QUOTE] thank you! I was having a bit of trouble on this for awhile now
Sorry, you need to Log In to post a reply to this thread.