• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

GlobalEvent Lottery System!

i get this erro on web.. >P
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field list'' in C:\xampp\htdocs\lottery.php:2 Stack trace: #0 C:\xampp\htdocs\lottery.php(2): PDO->query('SELECT id, name...') #1 C:\xampp\htdocs\index.php(82): include('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\lottery.php on line 2
 
vDk, scripter guy that is already in my otserv.
Perfect guy this script.
Congratulations
Scripter Perfect.
 
@up. uhm if getPlayerLevel(winner) > 9 then ...etc
 
@vDk
I really suggest you to fix that bug, if there are no players online then the console gets an error because of no one online. here's a lua fix:
Lua:
-- by vDk
local config = {
    lottery_hour = "3 Hours", -- Time to next lottery (only for broadcast message, real time you can set on globalevents.xml)
    rewards_id = {2494, 2472, 2514, 2160}, -- Rewards ID
    crystal_counts = 10, -- Used only if on rewards_id is crystal coin (ID: 2160).
    website = "yes" -- Only if you have php scripts and table `lottery` in your database!
    }
function onThink(interval, lastExecution)
    if getWorldCreatures(0) > 0 then
	
	 local list = {}
    for i, tid in ipairs(getPlayersOnline()) do
    list[i] = tid
end

        local winner = list[math.random(1, #list)]
        local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
        
        if(random_item == 2160) then
                doPlayerAddItem(winner, random_item, config.crystal_counts)
                doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(winner) .. ", Reward: " .. config.crystal_counts .. " " .. getItemNameById(random_item) .. "s! Congratulations! (Next Lottery in " .. config.lottery_hour .. ")")
        else
                doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(winner) .. ", Reward: " .. getItemNameById(random_item) .. "! Congratulations! (Next Lottery in " .. config.lottery_hour .. ")")
                doPlayerAddItem(winner, random_item, 1)
        end
        
        if(config.website == "yes") then
                db.executeQuery("INSERT INTO `lottery` (`name`, `item`) VALUES ('".. getCreatureName(winner) .."', '".. getItemNameById(random_item) .."');")
        end
        return true
	end
	return true
end
 
@Cybermaster
Thanks, first post has been updated.

@down
Hmm, i don't know how to fix it im low in php :(
 
Last edited:
How do you fix so that its impossible for a gamemaster to win the item?
 
Code:
-- by vDk
local config = {
    lottery_hour = "3 Hours", -- Time to next lottery (only for broadcast message, real time you can set on globalevents.xml)
			rewards_id = {5887, 5875, 6097, 6098, 6489, 7887, 2170, 10220, 7889, 8855, 2426, 2381, 7436, 2435, 7419, 3976, 5091, 2580, 5710, 5942, 7430, 7415, 2423, 7379, 2393, 8910, 8922, 8900, 2475, 2470, 2648, 2464, 2481, 2457, 7886, 2201, 2460, 2478, 2467, 2649, 2171, 2476, 2463, 2647, 2195, 2520, 2488, 2160}, -- Rewards ID
    crystal_counts = 1, -- Used only if on rewards_id is crystal coin (ID: 2160).
    website = "yes" -- Only if you have php scripts and table `lottery` in your database!
    }
function onThink(interval, lastExecution)
    if getWorldCreatures(0) > 0 then
        
         local list = {}
    for i, tid in ipairs(getPlayersOnline()) do
    list[i] = tid
end

        local winner = list[math.random(1, #list)]
        local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
        
        if(random_item == 2160) then
                doPlayerAddItem(winner, random_item, config.crystal_counts)
                doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(winner) .. ", Reward: " .. config.crystal_counts .. " " .. getItemNameById(random_item) .. "s! Congratulations! (Next Lottery in " .. config.lottery_hour .. ")")
        else
                doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(winner) .. ", Reward: " .. getItemNameById(random_item) .. "! Congratulations! (Next Lottery in " .. config.lottery_hour .. ")")
                doPlayerAddItem(winner, random_item, 1)
        end
        
        if(config.website == "yes") then
                db.executeQuery("INSERT INTO `lottery` (`name`, `item`) VALUES ('".. getCreatureName(winner) .."', '".. getItemNameById(random_item) .."');")
        end
        return true
        end
        return true
end

@ up, where do i put that code of yours?
 
Code:
-- by vDk
local config = {
    lottery_hour = "3 Hours", -- Time to next lottery (only for broadcast message, real time you can set on globalevents.xml)
			rewards_id = {5887, 5875, 6097, 6098, 6489, 7887, 2170, 10220, 7889, 8855, 2426, 2381, 7436, 2435, 7419, 3976, 5091, 2580, 5710, 5942, 7430, 7415, 2423, 7379, 2393, 8910, 8922, 8900, 2475, 2470, 2648, 2464, 2481, 2457, 7886, 2201, 2460, 2478, 2467, 2649, 2171, 2476, 2463, 2647, 2195, 2520, 2488, 2160}, -- Rewards ID
    crystal_counts = 1, -- Used only if on rewards_id is crystal coin (ID: 2160).
    website = "yes" -- Only if you have php scripts and table `lottery` in your database!
    }
function onThink(interval, lastExecution)
    if getWorldCreatures(0) > 0 then
        
         local list = {}
    for i, tid in ipairs(getPlayersOnline()) do
    list[i] = tid
	if (getPlayerAccess(tid) >= 2) then
		return true
	end
end

        local winner = list[math.random(1, #list)]
        local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
        
        if(random_item == 2160) then
                doPlayerAddItem(winner, random_item, config.crystal_counts)
                doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(winner) .. ", Reward: " .. config.crystal_counts .. " " .. getItemNameById(random_item) .. "s! Congratulations! (Next Lottery in " .. config.lottery_hour .. ")")
        else
                doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(winner) .. ", Reward: " .. getItemNameById(random_item) .. "! Congratulations! (Next Lottery in " .. config.lottery_hour .. ")")
                doPlayerAddItem(winner, random_item, 1)
        end
        
        if(config.website == "yes") then
                db.executeQuery("INSERT INTO `lottery` (`name`, `item`) VALUES ('".. getCreatureName(winner) .."', '".. getItemNameById(random_item) .."');")
        end
        return true
        end
        return true
end
 
I found bug when player nick = (Craisler's) error

PHP:
mysql_real_query(): INSERT INTO `lottery` (`name`, `item`) VALUES ('Craisler's', 'mastermind shield'); - MYSQL ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's', 'mastermind shield')' at line 1 (1064)
 
IF USING GIESOR ACC WEBPAGE USE THIS IN LAYOUT.PHP ALSO TOPIC LEADER ADD THIS ALSO


PHP:
</a>
<a href='?subtopic=lottery'>
  <div id='submenu_lottery' class='Submenuitem' onMouseOver='MouseOverSubmenuItem(this)' onMouseOut='MouseOutSubmenuItem(this)'>
    <div class='LeftChain' style='background-image:url(<?PHP echo $layout_name; ?>/images/general/chain.gif);'></div>
    <div id='ActiveSubmenuItemIcon_signatures' class='ActiveSubmenuItemIcon' style='background-image:url(<?PHP echo $layout_name; ?>/images/menu/icon-activesubmenu.gif);'></div>
    <div class='SubmenuitemLabel'>Lottery</div>
    <div class='RightChain' style='background-image:url(<?PHP echo $layout_name; ?>/images/general/chain.gif);'></div>
  </div>
 
I found bug when player nick = (Craisler's) error

PHP:
mysql_real_query(): INSERT INTO `lottery` (`name`, `item`) VALUES ('Craisler's', 'mastermind shield'); - MYSQL ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's', 'mastermind shield')' at line 1 (1064)

You have to escape the name.
I dont really remember how the function was called, but lets try. Find in the script getCreatureName(pid?) and change it to db.escapeString(getCreatureName(pid?)).

pid? -> I dont know what paramater he used and am too lazy to just read the script 8D
 
Thank you

I would just like to point out what a wonder job you did with this mod its not perfect but it works great and its a very stable code.
my server thanks you and so does the community!

also using latest tfs 3.6+ forgotten server and it works great!

grade A stuff here Thanks again! :D
 
Thanks!

Does it work to make like this?
Code:
if(random_item == STACKABLE) then
so all stackable items work instead of just crystal coin. else I will have to add
Code:
if(random_item == ID) then
for every stackable item I want :p
 
Back
Top