• Help with stopping people buying items.
    2 replies, posted
Any idea why I get the message "Please wait for the round to start before you buy anything." every time I try buy a second thing? e.g. I buy Traitor and then I buy a gun and I can't buy the gun. [lua] local _date = os.date("%b") .. os.date("%d") local _R = debug.getregistry() Store.TTable = {} Store.DTable = {} function _R.Player:StoreInitialize( ) tmysql.query( "SELECT value FROM tokens WHERE steamid = '" .. self:SteamID() .. "'", function( tokens ) if !tokens or #tokens == 0 then tmysql.query( "INSERT INTO tokens VALUES( '" .. self:Nick() .. "', '" .. self:SteamID() .. "', '" .. 5 .. "' )" ) self:SetNWInt("tokens", 5) else self:SetNWInt("tokens", tonumber( tokens[1][1] ) ) end end) tmysql.query( "SELECT value FROM lastjoin WHERE steamid = '" .. self:SteamID() .. "'", function( date ) if !date or !date[1] then tmysql.query( "INSERT INTO lastjoin VALUES( '" .. self:SteamID() .. "', '" .. tmysql.escape(_date) .. "' )" ) if self:IsAdmin() or self:IsUserGroup("vip") or self:IsUserGroup("moderator") then self:SetNWInt("tokens", self:GetNWInt("tokens") + 20) else self:SetNWInt("tokens", self:GetNWInt("tokens") + 1) end else if date[1][1] != _date then tmysql.query( "UPDATE lastjoin SET value = '" .. tmysql.escape(_date) .. "' WHERE steamid = '" .. self:SteamID() .. "'", SQLHandle ) if self:IsAdmin() or self:IsUserGroup("vip") or self:IsUserGroup("moderator") then self:SetNWInt("tokens", self:GetNWInt("tokens") + 20) else self:SetNWInt("tokens", self:GetNWInt("tokens") + 1) end end end end) end function _R.Player:Save( ) local cash = tonumber(self:GetNWInt("tokens")) tmysql.query( "UPDATE tokens SET value = '" .. cash .. "' WHERE steamid = '" .. self:SteamID() .. "'", SQLHandle ) end function _R.Player:AddTokens( n ) if !n then return end math.floor(tonumber(n)) self:SetNWInt("tokens", self:GetNWInt("tokens") + n) self:Save() end function _R.Player:TakeTokens( n ) if !n then return end math.floor(tonumber(n)) self:SetNWInt("tokens", self:GetNWInt("tokens") - n) self:Save() end function _R.Player:BuyItem( id ) if self:CanBuy() != false then self.BoughtT = 0 local id = tonumber(id) if id == 0 then if self:GetRole() == ROLE_TRAITOR or ROLE_DETECTTIVE then self:SetCredits(self:GetCredits() + 1) self:TakeTokens( Store.ItemsTable[id][2] ) self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens." ) else self:ChatPrint("You must be a Traitor or a Detective to buy credits.") end elseif id == 1 then local found = false if self.ForceDetective then return end self.ForceTraitor = true if PlayerCount() >= 8 then for k, v in pairs(player.GetAll()) do if v.ForceTraitor then if table.Count(Store.TTable) <= GetTMax() then table.insert(Store.TTable, v:Nick()) else self:ChatPrint("Too many people have bought traitor for next round.") found = true self.ForceTraitor = false end end end if !found then self.boughtT = self.boughtT + 1 self:TakeTokens( Store.ItemsTable[id][2] ) self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens" ) self:ChatPrint( "You will be made " .. Store.ItemsTable[id][1] .. " next round." ) end else self:ChatPrint("Please wait for more people to join before you buy Traitor.") self.ForceTraitor = false end elseif id == 2 then local found = false if self.ForceTraitor then return end if PlayerCount() >= 8 then for k, v in pairs(player.GetAll()) do if v.ForceDetective then if table.Count(Store.TTable) <= GetDMax() then table.insert(Store.DTable, v:Nick()) else self:ChatPrint("Too many people have bought detective for next round.") found = true self.ForceDetective = false end end end if !found then self.ForceDetective = true self:TakeTokens( Store.ItemsTable[id][2] ) self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens" ) self:ChatPrint( "You will be made " .. Store.ItemsTable[id][1] .. " next round." ) end end elseif id == 3 then if self:CanBuy() == false or "tord" then self:ChatPrint("Please wait for the round to start before you buy anything.") else for k, v in pairs(Store.SecondaryWeaponTable) do if self:HasWeapon(v[1]) then self:DropNamedWeapon(v[1]) break end end self:Give("weapon_zm_pistol") self:GiveAmmo(60, "Pistol") self:TakeTokens( Store.ItemsTable[id][2] ) self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens." ) end elseif id == 4 then if self:CanBuy() == false or "tord" then self:ChatPrint("Please wait for the round to start before you buy anything.") else for k, v in pairs(Store.SecondaryWeaponTable) do if self:HasWeapon(v[1]) then self:DropNamedWeapon(v[1]) break end end self:Give("weapon_ttt_glock") self:GiveAmmo(60, "Pistol") self:TakeTokens( Store.ItemsTable[id][2] ) self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens." ) end elseif id == 5 then if self:CanBuy() == false or "tord" then self:ChatPrint("Please wait for the round to start before you buy anything.") else for k, v in pairs(Store.SecondaryWeaponTable) do if self:HasWeapon(v[1]) then self:DropNamedWeapon(v[1]) break end end self:Give("weapon_zm_revolver") self:GiveAmmo(36, "AlyxGun") self:TakeTokens( Store.ItemsTable[id][2] ) self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens." ) end elseif id == 6 then if self:CanBuy() == false or "tord" then self:ChatPrint("Please wait for the round to start before you buy anything.") else for k, v in pairs(Store.PrimaryWeaponTable) do if self:HasWeapon(v[1]) then self:DropNamedWeapon(v[1]) break end end self:Give("weapon_zm_shotgun") self:GiveAmmo(24, "Buckshot") self:TakeTokens( Store.ItemsTable[id][2] ) self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens." ) end elseif id == 7 then if self:CanBuy() == false or "tord" then self:ChatPrint("Please wait for the round to start before you buy anything.") else for k, v in pairs(Store.PrimaryWeaponTable) do if self:HasWeapon(v[1]) then self:DropNamedWeapon(v[1]) break end end self:Give("weapon_zm_sledge") self:TakeTokens( Store.ItemsTable[id][2] ) self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens." ) end elseif id == 8 then if self:CanBuy() == false or "tord" then self:ChatPrint("Please wait for the round to start before you buy anything.") else for k, v in pairs(Store.PrimaryWeaponTable) do if self:HasWeapon(v[1]) then self:DropNamedWeapon(v[1]) break end end self:Give("weapon_zm_rifle") self:GiveAmmo(20, "357") self:TakeTokens( Store.ItemsTable[id][2] ) self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens." ) end elseif id == 9 then if self:CanBuy() == false or "tord" then self:ChatPrint("Please wait for the round to start before you buy anything.") else for k, v in pairs(Store.PrimaryWeaponTable) do if self:HasWeapon(v[1]) then self:DropNamedWeapon(v[1]) break end end self:Give("weapon_zm_mac10") self:GiveAmmo(60, "SMG1") self:TakeTokens( Store.ItemsTable[id][2] ) self:ChatPrint( "You bought " .. Store.ItemsTable[id][1] .. " for " .. tonumber(Store.ItemsTable[id][2]) .. " tokens." ) end else if self:CanBuy() == false or "tord" then self:ChatPrint("Please wait for the rou
Change every [lua]if self:CanBuy() == false or "tord" then[/lua] to [lua]if not self:CanBuy() then[/lua]and in lines 238-249 change every [lua]return "tord"[/lua] to [lua]return false[/lua] Basically, what you were doing is asking along the lines of "If self:CanBuy is equal to false, or if the string "tord" is valid", when what you really wanted is "If self:CanBuy is not true" When you put it in an if statement, a string value is always assumed to be true
[QUOTE=my_hat_stinks;38873604] Basically, what you were doing is asking along the lines of "If self:CanBuy is equal to false, or if the string "tord" is valid", when what you really wanted is "If self:CanBuy is not true" When you put it in an if statement, a string value is always assumed to be true[/QUOTE] Oh thanks :D I didn't know that :)
Sorry, you need to Log In to post a reply to this thread.