-
Member
Is There A Script For Random Player To Get Max Level (X Amount Of Players Online)
I remember joining a server long long ago when there was like 100+ people online at once
1 random lucky winner gets max level instantly and it would congratulate them ect ect
is there a script out there to get for that? or did they make it themselfs?
-
It would be pretty simple.
Psuedocode:
Code:
local MAX_LEVEL = 80
function RewardRandomPlayer()
for _,v in pairs(GetOnlinePlayers()) do
if v and v:GetLevel() < MAX_LEVEL and math.random(1, 1000) == 1 then -- 1/1000 chance, this is not good random number generation
v:SetLevel(MAX_LEVEL)
v:SendChatMessageToPlayer(v, "You have won some random thing that gives you max level. Enjoy.")
break -- only possible to reward 1 player per function call, this exits the for loop
end
end
end
Update function calls to one valid with your Lua engine if you are using one ( Eluna API ).
Same logic applies to C++.
Call function every X seconds.
If you want to reward a player always:
Code:
local MAX_LEVEL = 80
function RewardRandomPlayer()
local plrs = GetOnlinePlayers()
if #plrs > 0 then
local rewarded = false
local tries = 0
local maxTries = 10
while not rewarded do
for _,v in pairs(plrs) do
if v and v:GetLevel() < MAX_LEVEL and math.random(1, 1000) == 1 then -- 1/1000 chance, this is not good random number generation
v:SetLevel(MAX_LEVEL)
v:SendChatMessageToPlayer(v, "You have won some random thing that gives you max level. Enjoy.")
rewarded = true -- exit while loop
break -- only possible to reward 1 player per function call, this exits the for loop
end
end
tries = tries + 1
if tries > maxTries then
break -- exit loop if failed to reward a player after maxLoops
end
end
end
end
Although this is hacky. Better yet:
Code:
local MAX_LEVEL = 80
function RewardRandomPlayer()
local plrs = GetOnlinePlayers()
if #plrs > 0 then
local rewarded = false
local tries = 0
local maxTries = 10
while not rewarded do
local v = plrs[math.random(1, #plrs)] -- get a random player from the plr table
if v and v:GetLevel() < MAX_LEVEL then
v:SetLevel(MAX_LEVEL)
v:SendChatMessageToPlayer(v, "You have won some random thing that gives you max level. Enjoy.")
rewarded = true -- exit while loop
break -- only possible to reward 1 player per function call, this exits the for loop
end
tries = tries + 1
if tries > maxTries then
break -- exit loop if failed to reward a player after maxLoops
end
end
end
end
You could touch it up for your needs.
Last edited by stoneharry; 09-20-2018 at 02:41 PM.
-
Post Thanks / Like - 1 Thanks
jakeyup (1 members gave Thanks to stoneharry for this useful post)
-
Member
Originally Posted by
stoneharry
It would be pretty simple.
Psuedocode:
Code:
local MAX_LEVEL = 80
function RewardRandomPlayer()
for _,v in pairs(GetOnlinePlayers()) do
if v and v:GetLevel() < MAX_LEVEL and math.random(1, 1000) == 1 then -- 1/1000 chance, this is not good random number generation
v:SetLevel(MAX_LEVEL)
v:SendChatMessageToPlayer(v, "You have won some random thing that gives you max level. Enjoy.")
break -- only possible to reward 1 player per function call, this exits the for loop
end
end
end
Update function calls to one valid with your Lua engine if you are using one (
Eluna API ).
Same logic applies to C++.
Call function every X seconds.
If you want to reward a player always:
Code:
local MAX_LEVEL = 80
function RewardRandomPlayer()
local plrs = GetOnlinePlayers()
if #plrs > 0 then
local rewarded = false
local tries = 0
local maxTries = 10
while not rewarded do
for _,v in pairs(plrs) do
if v and v:GetLevel() < MAX_LEVEL and math.random(1, 1000) == 1 then -- 1/1000 chance, this is not good random number generation
v:SetLevel(MAX_LEVEL)
v:SendChatMessageToPlayer(v, "You have won some random thing that gives you max level. Enjoy.")
rewarded = true -- exit while loop
break -- only possible to reward 1 player per function call, this exits the for loop
end
end
tries = tries + 1
if tries > maxTries then
break -- exit loop if failed to reward a player after maxLoops
end
end
end
end
Although this is hacky. Better yet:
Code:
local MAX_LEVEL = 80
function RewardRandomPlayer()
local plrs = GetOnlinePlayers()
if #plrs > 0 then
local rewarded = false
local tries = 0
local maxTries = 10
while not rewarded do
local v = plrs[math.random(1, #plrs)] -- get a random player from the plr table
if v and v:GetLevel() < MAX_LEVEL then
v:SetLevel(MAX_LEVEL)
v:SendChatMessageToPlayer(v, "You have won some random thing that gives you max level. Enjoy.")
rewarded = true -- exit while loop
break -- only possible to reward 1 player per function call, this exits the for loop
end
tries = tries + 1
if tries > maxTries then
break -- exit loop if failed to reward a player after maxLoops
end
end
end
end
You could touch it up for your needs.
holy cow. you are literally a god im surprised no one said google. com or whatever or give me bs answers.
we need more people like you in the community <3
much love dude
-
Originally Posted by
jakeyup
holy cow. you are literally a god im surprised no one said google. com or whatever or give me bs answers.
we need more people like you in the community <3
much love dude
It only takes a couple of minutes to offer some pointers. Glad to help.
The code could be improved - I only wrote it quickly to show the basic concepts. For example, if there are a lot of max level players online it becomes less likely for a player to get rewarded. Instead you could remove all max level players from the players table before getting a random player from the table.