• Client and Server problem
    1 replies, posted
Recently I made a tab in the creator menu. I got everything working, the player can spawn whatever is on the menu. But I ran into a problem in mulitplayer. In multiplayer only the server owner is able to spawn the items on the menu. If a regular player tries it, nothing happens. Here is the codes (A lot of the code will look very similar to the GMod's creator menu, because I got a lot of the code from there): This is running on client side: [code] local gmod_npcweapon = CreateConVar("gmod_npcweapon","",{FCVAR_ARCHIVE}) spawnmenu.AddContentType( "vjbase_npc", function( container, obj ) if ( !obj.material ) then return end if ( !obj.nicename ) then return end if ( !obj.spawnname ) then return end if ( !obj.weapon ) then obj.weapon = { "" } end local icon = vgui.Create( "ContentIcon", container ) icon:SetContentType( "vjbase_npc" ) icon:SetSpawnName( obj.spawnname ) icon:SetName( obj.nicename ) icon:SetMaterial( obj.material ) icon:SetAdminOnly( obj.admin ) icon:SetNPCWeapon( obj.weapon ) icon:SetColor(Color(244,164,96,255)) icon.DoClick = function() local weapon = table.Random( obj.weapon ) if ( gmod_npcweapon:GetString() != "" ) then weapon = gmod_npcweapon:GetString() end RunConsoleCommand( "vjbase_spawnnpc", obj.spawnname, weapon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) end icon.OpenMenu = function( icon ) local menu = DermaMenu() local weapon = table.Random( obj.weapon ) if ( gmod_npcweapon:GetString() != "" ) then weapon = gmod_npcweapon:GetString() end menu:AddOption( "Copy to Clipboard", function() SetClipboardText( obj.spawnname ) end ) menu:AddOption( "Spawn Using Toolgun", function() RunConsoleCommand( "gmod_tool", "creator" ) RunConsoleCommand( "creator_type", "2" ) RunConsoleCommand( "creator_name", obj.spawnname ) RunConsoleCommand( "creator_arg", weapon ) end ) menu:AddSpacer() menu:AddOption( "Delete", function() icon:Remove() hook.Run( "SpawnlistContentChanged", icon ) end ) menu:Open() end if (IsValid(container)) then container:Add(icon) end return icon end) [/code] Then we go to a shared file: [code] function VJSPAWN_NPC( player, NPCClassName, WeaponName, tr ) if (CLIENT) then return end and then rest of the code... end concommand.Add( "vjbase_spawnnpc",function(ply,cmd,args) VJSPAWN_NPC(ply,args[1],args[2]) end) [/code] This is where the problem is, this function is only running for the owner because it's server side only. If I make it client side, also it will make errors because I use a lot of server sided functions such as "undo.create" or "ents.create" Thanks for the help!
Bump
Sorry, you need to Log In to post a reply to this thread.