Hello, i'm trying to get a randomizing every spawn system, get my Weapons spawn a bit randomly
from a M4A1 to Ak47 or something like that.
Also trying to make this rarer then the other.
[code]
local items = {}
items[1] = "item_p226"
items[2] = "item_m4a1"
items[3] = "item_ak47"
items[4] = "item_badges"
local item = ""
local rand = math.random(1,4)
if items[1] then
item = "item_p226"
elseif items[2] then
item = "item_m4a1"
elseif items[3] then
item = "item_ak47"
elseif items[4] then
item = "item_badges"
end
local Weaponspawn1 = ents.Create(item)
Weaponspawn1:SetPos( Vector(-1716.065552, -11139.618164, -573.968750) )
Weaponspawn1:Spawn()
[/code]
which i was trying to make the rand will Randomly pick one of the tables for that spawn,
And i was wondering if i could do is like [code]
local items = {}
items[1] = {Name="item_p226", Rare=10}
[/code]
Which Name would be the Class it spawns, then Rare is 1 to Amount of rareness Chances to spawn.
Thanks, if you can help
Well... i think you could make it like:
maximum of rareness is 10, then you sort an number between 0 and 10, if the number of rareness is between 0 and the sorted number, it will select it(but if you thik well, it could sort more than one option)
[editline]14th September 2014[/editline]
Yeah, i know this idea looks a little stupid, but its the only thing i can think of..
Probably shit method. I don't know how to implement the rarity properly or how you want it implemented.
[code]
local items = {}
items[1] = {"item_p226", 10 }
items[2] = {"item_m4a1", 20 }
items[3] = {"item_ak47", 20 }
items[4] = {"item_badges", 10 }
function GenerateWeapon()
local item = ""
local rand = math.random(1,#items)
item = items[rand][1]
rand = math.random(1,100)
if rand >= items[rand][2] then
local Weaponspawn1 = ents.Create(item)
Weaponspawn1:SetPos( Vector(-1716.065552, -11139.618164, -573.968750) )
Weaponspawn1:Spawn()
else
rand = nil
item = nil
GenerateWeapon()
end
end
[/code]
Yeah, after reading what i've wrote, i realized it was a really shitty method, sorry for wasting your time :P
Sorry, you need to Log In to post a reply to this thread.