Shawak
Intermediate OT User
Author:
Version: 1.0
Informations:
Install:
I hope you like it!
Regards,
Shawak
-
(Credits for unwritten "lottery.send" function to Chojrak)
Version: 1.0
Informations:
- Tested on TFS 0.3.5pl1.
- The script is BETA stage.
- Please report any bugs/ideas, thanks.
- This Npc send all time (editable), a reward (editable), to one of the people they joined the lottery,
then it delete the list of joined players and the lottery start again. - To join you have to be an employed and you have to pay an employed price.
- Put the Npc on the map and players can buy their tickets their.
- Warning: Only 1 Npc on the map, or it will become bugged!
- Config:
- mailBoxPos: Position of a mailbox on your map.
- lottery_storage: Storage where the time of the lottery will be saved.
- lottery_each_minutes: Minutes for each lottery drawing.
- min_people_for_lottery: Min. People for the drawing, if there are not enaught, there won't be any drawing.
- multiple_Join:
- "yes" = Players are able to join more then one time.
- "no" = Players can only join one time for one drawing.
- level_to_join: Only players they have the level (or higher) are able to join.
- cost: The amount that you have to pay if you want join he lottery.
- rewards: Lottery rewards.
Install:
- Go to your database and excute this query:
Lua:CREATE TABLE `lottery` ( `name` varchar(255) )
- data/npcs/Lottery Guy.xml
Lua:<?xml version="1.0" encoding="UTF-8"?> <npc name="Lottery Guy" nameDescription="the Lottery Guy" script="lottery.lua" walkinterval="2000" floorchange="0" skull="green"> <health now="100" max="100"/> <look type="130" head="39" body="122" legs="125" feet="57" addons="0"/> </npc>
- data/npcs/scripts/lottery.lua
Lua:--[[ Lottery Npc Version 1.0 by Shawak ]]-- local config = { mailBoxPos = {x = 997, y = 1033, z = 7}, lottery_storage = 8888, lottery_each_minutes = 24 * 60, min_people_for_lottery = 1, multiple_Join = "no", level_to_join = 50, cost = 10000, rewards = { { {2160, 100}, -- 100 cc {2160, 10} -- 10 cc }, { {2494, 1} -- demon armor }, { {2514, 1} -- mastermind shield }, { {2112, 1} -- teddy bear } }} -------- config end -------- {{ local lottery = { -- don't touch add = function(cid, often) if often == 1 then db.executeQuery("INSERT INTO `lottery` (`name`) VALUES ('"..getCreatureName(cid).."');") else for o = 1, often do db.executeQuery("INSERT INTO `lottery` (`name`) VALUES ('"..getCreatureName(cid).."');") end end return true end, delete = function() return db.executeQuery("DELETE FROM `lottery`;") end, get = function() local players = {} local players_db = db.getResult("SELECT `name` FROM `lottery`;") if players_db:getID() ~= -1 then while TRUE do table.insert(players, players_db:getDataString("name")) if not(players_db:next()) then break end end players_db:free() end return players end, send = function(name, town, items, notify) local random = 0 local parcel = doCreateItemEx(2595) local backpack = doCreateItemEx(1988) local label = doAddContainerItem(parcel, 2599) local letter = doAddContainerItem(parcel, 2597) doSetItemText(label, name .."\n".. town) doSetItemText(letter, "Hello "..name..",\nYou won the lottery,\nthis backpack conatins your rewards!\nBe happy with it!") random = math.random(1, #items) for i = 1, #items[random] do doAddContainerItem(backpack, items[random][i][1], items[random][i][2]) end doAddContainerItemEx(parcel, backpack) if (notify == TRUE) then local player = getPlayerByNameWildcard(name) if isPlayer(player) == TRUE then doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, "New Mail of the lottery arrived.") end end return doTeleportThing(parcel, config.mailBoxPos) end } -- Npc if getGlobalStorageValue(config.lottery_storage) == -1 then setGlobalStorageValue(config.lottery_storage, os.time()) end local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} local time = config.lottery_each_minutes * 60 function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end function onThink() npcHandler:onThink() if getGlobalStorageValue(config.lottery_storage) < os.time() then setGlobalStorageValue(config.lottery_storage, os.time() + time) local players_lottery = lottery.get() if #players_lottery == 0 then doBroadcastMessage("Nobody won the lottery, because no one joined.", 22) elseif #players_lottery < config.min_people_for_lottery then doBroadcastMessage("Nobody won the lottery, to few people joined.", 22) else local winner_of_lottery = players_lottery[math.random(1, #players_lottery)] local town = db.getResult("SELECT `town_id` FROM `players` WHERE `name` = '"..winner_of_lottery.."';") if town:getDataInt("town_id") == 0 then return print(winner_of_lottery.." have no hometown, he aren't able to get the price of the lottery.") end doBroadcastMessage(""..winner_of_lottery.." won the lottery.", 22) lottery.send(winner_of_lottery, getTownName(town:getDataInt("town_id")), config.rewards, TRUE) town:free() end lottery.delete() end return TRUE end function creatureSayCallback(cid, type, msg) if(not npcHandler:isFocused(cid)) then return false end local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if msgcontains(msg, 'lottery') then selfSay('Do you want to join the lottery for '..config.cost..' gold coins?', cid) talkState[talkUser] = 1 elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then local check = db.getResult("SELECT * FROM `lottery` WHERE `name` = '"..getCreatureName(cid).."';") if string.lower(config.multiple_Join) == "yes" or check:getID() == -1 and string.lower(config.multiple_Join) == "no" then if string.lower(config.multiple_Join) == "no" then check = nil end if getPlayerLevel(cid) >= config.level_to_join then if doPlayerRemoveMoney(cid, config.cost) == TRUE then selfSay('I added you to the {lottery}!', cid) lottery.add(cid, 1) talkState[talkUser] = 0 else selfSay('You need '..config.cost..' gold coins to join the {lottery}!', cid) talkState[talkUser] = 0 end else selfSay('You have to be level '..config.level_to_join..' or higher to join the {lottery}.', cid) talkState[talkUser] = 0 end else selfSay('I already added yu to the {lottery}.', cid) talkState[talkUser] = 0 end end return TRUE end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:setMessage(MESSAGE_GREET, 'Hello |PLAYERNAME|, I can add you to the {lottery}!') npcHandler:setMessage(MESSAGE_WALKAWAY, 'Bye |PLAYERNAME|!') npcHandler:setMessage(MESSAGE_FAREWELL, 'See you later |PLAYERNAME|!') npcHandler:addModule(FocusModule:new())
- For Acc Page (if you want):
Lua:<?PHP $lottery = $SQL->query('SELECT `lottery`.`name` FROM `lottery` ORDER BY `lottery`.`name` DESC'); $players = 0; $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD CLASS=white><b>Insturction<b></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD><center><b>Here you can see all players who joined the lottery.</b></center></TR></TD></TABLE><br />'; if(empty($lottery)) { $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=10%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD CLASS=white><b>Lottery</b></td></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD>Nobody joined the lottery</TD></TR></TABLE>'; $main_content .= '<br /><p align="right"><small>System created by <a href="http://otland.net/members/Shawak/">Shawak</a>.</small></p>'; } else { foreach($lottery as $lottery) { $players++; if(is_int($players / 2)) $bgcolor = $config['site']['lightborder']; else $bgcolor = $config['site']['darkborder']; $content .= '<TR BGCOLOR='.$bgcolor.'><TD><left>'.$players.'</left></TD><TD><left>'.$lottery['name'].'</left></TD></TR>'; } $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD CLASS=white><b>#</b></TD><TD CLASS=white><b><left>Name</lefft></b></TD></TR>'.$content.'</TABLE>'; $main_content .= '<br /><p align="right"><small>System created by <a href="http://otland.net/members/Shawak/">Shawak</a>.</small></p>'; } ?>
I hope you like it!
Regards,
Shawak
Last edited: