Forum

> > CS2D > Scripts > random id
Forums overviewCS2D overview Scripts overviewLog in to reply

English random id

2 replies
To the start Previous 1 Next To the start

old random id

sadswsww
User Off Offline

Quote
I'm having problem with LUA script.
I planned to write a Lua: only 1 random player will be equipped Ak-74 when A ROUND STARTS ONLY (in zombie mode) and if that player became a zombie, he wont get Ak-74. :D.

This is my LUA. You can check and fix for me
Spoiler >


Plz help me.
Thanks a lot

Admin/mod comment

You don't have to create 2 same thread in a different name, please don't create multiple threads next time. I removed the other one. /Zeroarcanus

old Re: random id

Rainoth
Moderator Off Offline

Quote
1
math.random(1,5)
Would be correct if you want to get a number between 1 and 5, but you also have to check if player exists with that id. I'd advise to use cs2d lua cmd player table and get a random value from "tableliving".

old Re: random id

Starkkz
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
addhook("startround","onStart")
function onStart()
local Players = player(0, "tableliving")
local TableIndex = math.random(1, #Players)
local ID = Players[TableIndex]
if ID and player(ID, "exists") then
parse("equip "..ID.." 30")
end
end
Should be shorter. Sorry about the tabs, I was on mobile phone.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview