• Shop System Lua Problem
    5 replies, posted
Hello, so it seems I have been having troubles with two function I wrote myself (SetDoorStatus(num, enabled), GetDoorStatus(num)) for the past four hours, trying to figure out what's wrong, but found nothing. When I buy a door it does not set the door status of "Opened" to true. On the SetDoorStatus function it's supposed to say "Test 2", but it didn't print, but when I ran it from the console manually it printed "Test 2". It also doesn't print an error to the console. Door Name Layout: shop door doorNum num doorCost When I run these in the console (lua_run SetDoorStatus(1, true)) they work perfectly fine! [CODE]function SetDoorStatus(num, enable) for _, d in pairs(ents.FindByClass("prop_door_rotating")) do sep = string.Explode(" ", d:GetName()) if tonumber(sep[2]) == num then print("Test 2") d:SetNWBool("Opened", enable) end end end function GetDoorStatus(num) for _, d in pairs(ents.FindByClass("prop_door_rotating")) do sep = string.Explode(" ", d:GetName()) if tonumber(sep[2]) == num then return d:GetNWBool("Opened", false) end end return false end function DoorShopInfo(ent, shop, ply) local doorNum = shop[3] local num = shop[4] local shopDoorPrice = tonumber(shop[5]) if GetDoorStatus(doorNum) == false then ply:SetNWString("Info", "Press F To Buy Door For $" .. tostring(shopDoorPrice)) ply:SetNWBool("ShowInfo", true) end end function DoorShop(ent, shop, ply) local doorNum = shop[3] local num = shop[4] local shopDoorPrice = tonumber(shop[5]) if GetDoorStatus(doorNum) == false and ply:GetNWInt("Cash") >= shopDoorPrice then SetDoorStatus(doorNum, true) SetZombieSpawnsEnabled(num, true) ply:SetNWInt("Cash", ply:GetNWInt("Cash") - shopDoorPrice) for _, d in pairs(ents.FindByName("door " .. doorNum)) do d:Fire("unlock", "", 0) d:Fire("open", "", 0) d:Fire("lock", "", 0) end ply:ChatPrint("You have baught a door!") end end hook.Add("PlayerButtonDown", "GunShop", function (ply, key) if key == KEY_F then for _, s in pairs(shops) do plys = ents.FindInBox(s:LocalToWorld(s:OBBMins()), s:LocalToWorld(s:OBBMaxs())) if table.HasValue(plys, ply) then local shopName = string.Explode(" ", s:GetName()) local shopType = shopName[2] if shopType == "weapon" then WeaponShop(shopName, ply) end if shopType == "door" then DoorShop(s, shopName, ply) end end end end end)[/CODE]
Anyone?
Make sure you're running them server-side; using PlayerButtonDown/Up / KeyDown/Up aren't reliable. But, I'm pretty sure they are clientside; if they are then make sure you network the purchase to the server.
All of this is server-side. I stopped using Networked Variables because I found out it's stupid to do that. So I just called variables onto the objects.
Well, the "PlayerButtonDown" hook is shared, so i think you'll need to run a part of it on the client(not sure about this)
Nope, Shared just means it can run on either or.
Sorry, you need to Log In to post a reply to this thread.