• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Lottery Npc v1.0

Shawak

Intermediate OT User
Joined
Sep 11, 2008
Messages
1,984
Solutions
2
Reaction score
119
Location
Germany
GitHub
Shawak
Author:
  • 33xar8m.jpg

    (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.
Description:
  • 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!
Instruction:
  • 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.
Screenshot:
33mv97d.png


Install:
  • Go to your database and excute this query:
    Lua:
    CREATE TABLE `lottery` (
      `name` varchar(255)
    )
Script:
  • 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:
Awesome! another Great Script of you Shawak,
Rep++ :D
 
You forgot to add, you rewrote my Mail Send function ;). Anyway good job :)
 
A global event with these features would be better.
But, good release.
 
Thanks, but i need VIP Tile :D

hey im a noob and i mady it myself are you kidding?








function onStepIn(cid, item, frompos, item2, topos)
queststatus = getPlayerStorageValue(cid,3553) --Not needed

playerpos = getPlayerPosition(cid)
novapos = {x=32, y=321, z=7} --destination

accountName = getPlayerAccount(cid)
if(isVip(accountName))then
time = getAccountVipTime(accountName)
if(time > 0)then

getThingfromPos(playerpos)
doSendMagicEffect(playerpos,2)
doTeleportThing(cid,novapos)
doPlayerSendTextMessage(cid,22,"now you are in the island!")
doSendMagicEffect(novapos,10)

else
doPlayerSendCancel(cid, "only vip players can go there.")
end
else
doPlayerSendTextMessage(cid,19, "You Are Not Vip.")
end
return TRUE
end


out of topic can you tell me what is wrong with this script?
Plz

local topLeft = {x=31931, y=32895, z=7}
local buttomRight = {x=31935, y=32901, z=7}
local newarea = {x=33089, y=31039, z=10}


function onUse(cid, item, fromPosition, itemEx, toPosition)
local monsters1 = getmonstersfromArea(topLeft, buttomRight)

for _, monster in pairs(monsters1) do
if getCreatureName(monster) == "Giada" then
doRemoveCreature(monster)
doSummonCreature("Giada", {x=31894,y=32880,z=6})
else
doPlayerSendCancel(cid, "Not posible")
end
end
return FALSE

end
 
My code:
PHP:
   <?PHP
$auctions = $SQL->query('SELECT `auction_system`.`player`, `auction_system`.`id`, `auction_system`.`item_name`, `auction_system`.`item_id`, `auction_system`.`count`, `auction_system`.`cost`, `auction_system`.`date`, `players`.`name` FROM `auction_system`, `players` WHERE `players`.`id` = `auction_system`.`player` ORDER BY `auction_system`.`id` DESC')->fetchAll();
$players = 0;
       
    $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD CLASS=white><b>Instruction<b></TD></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD><center><h2>Commands</h2><b>!offer add, itemName, itemPrice, itemCount</b><br /><small>example: !offer add, plate armor, 500, 1</small><br /><br /><B>!offer buy, AuctionID</b><br /><small>example: !offer buy, 1943</small><br /><br /><b>!offer remove, AuctionID</b><br /><small>example: !offer remove, 1943</small></center></TR></TD></TABLE><br />';
    if(empty($auctions))
    {
        $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD CLASS=white><b>Auctions</b></td></TR><TR BGCOLOR='.$config['site']['darkborder'].'><TD>Currently is no one active Auction.</TD></TR></TABLE>';
        $main_content .= '<br /><p align="right"><small>System created by <a href="http://otland.net/members/vDk/">vDk</a>.</small></p>';
    }
    else
    {
    foreach($auctions as $auction) {
        $players++;
            if(is_int($players / 2))
                $bgcolor = $config['site']['lightborder'];
            else
                $bgcolor = $config['site']['darkborder'];
        $cost = round($auction['cost']/1000, 2);
        $content .= '<TR BGCOLOR='.$bgcolor.'><TD><center>'.$auction['id'].'</center></TD><TD><center><img src="http://otland.net/images/items/'.$auction['item_id'].'.gif"/></center></TD><TD><center>'.$auction['item_name'].'</center></TD><TD><center><a href="?subtopic=characters&name='.urlencode($auction['name']).'">'.$auction['name'].'</a></center></TD><TD><center>'.$auction['count'].'</center></TD><TD><center>'.$cost.'k<br /><small>'.$auction['cost'].'gp</small></center></TD><TD><center>!offer buy, '.$auction['id'].'</center></TR>';
    }
    
    $main_content .= '<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR="'.$config['site']['vdarkborder'].'"><TD CLASS=white><b><center>ID</center></b></TD><TD class="white"><b><center>#</center></b></TD><TD class="white"><b><center>Item Name</center></b></TD><TD class="white"><b><center>Player</center></b></TD><TD class="white"><b><center>Count</center></b></TD><TD class="white"><b><center>Cost</center></b></td><TD class="white"><b><center>Buy</center></b></td></TR>'.$content.'</TABLE>';
    $main_content .= '<br /><p align="right"><small>System created by <a href="http://otland.net/members/vDk/">vDk</a>.</small></p>';
}
    ?>
"your" code:
PHP:
  <?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>';
}
?>

<_<
 
[07/02/2010 23:31:19] data/npc/scripts/lottery.lua:20: attempt to call global 'getLotteryList' (a nil value)
[07/02/2010 23:31:19] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/lottery.lua
 
Back
Top