local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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() end
local random_items = {2139,2461,6099,2663,2662,2665,3970,2458,2482,3971,3967,2460,6096,2473,2480,2481,2459,2457,2479,2490,2502,
3969,2491,2462,2499,3972,2506,2475,2497,2501,2342,2498,5741,2493,2474,2496,2343,2471,5461,2660,2664,2659,2658,2654,2655,2650,
2652,2651,2657,2485,2653,2467,2484,2464,2465,2483,3968,2463,2489,2503,2486,2656,2476,2487,2500,2466,2492,2505,2494,2508,2472,
3983,2649,2468,2648,2478,2647,2477,2504,2488,2495,2470,2469,2507,2642,2195,2358,2643,3982,2645,2646,2644,2641,5462,6132,2405,
2380,2386,2418,2388,2441,3965,2428,2378,3962,2429,3964,2435,2430,2425,2387,2381,2432,2426,2440,2427,2414,2431,2415,2447,2443,
6553,2416,2382,2448,2401,2449,2398,3966,2422,2439,2417,2321,2394,2423,2434,2436,2445,2433,2424,2391,2437,2444,2421,3961,2453,
2452,2403,2402,2404,2379,2550,2384,2396,2406,2420,2385,2376,2450,2395,2412,2442,2397,2411,2419,3963,2383,2413,2409,2377,2438,
2392,2407,2451,2446,2393,2400,6528,2390,6528,2456,2455,5803,1294,2111,2389,2410,2399,2544,2545,2546,2543,2547,6529,2512,2526,
2511,2510,2529,2530,2541,2509,2524,2531,3974,2513,2521,2540,2525,3975,2527,2532,3973,2518,6131,2538,2535,2533,2515,2516,2519,
2528,2537,2517,2536,2542,2534,2539,2520,6391,6433,2514,2522,2523,2454,6553,6132,2208,2209,2124,2213,2127,2167,2179,2168,2164,
2166,2214,2357,2123,2165,2207,2169,2211,2212,2215,2204,2205,2203,2216,2202,2210,2206,2121,2196,2173,2142,2138,2132,2172,2126,
2125,2201,2136,2198,2141,2199,2130,2171,2200,2133,2135,2661,2170,2132,2131,2197,2319,2161,2129,2144,2158,2318,2128,2160,3956,
2148,2155,2152,2156,2159,2134,2150,2145,2149,2147,2146,2151,2143,5022,2153,2154,2162,2163,2184,2181,2182,2183,2185,2186,2187,
2188,2189,2190,2191,2666,2671,2689,2691,2691,2696,2667,2679,2686,2668,2690,2684,2681,2673,2674,2676,2677,2685,2683,2680,2675,
2687,2695,2787,2788,2789,2790,2791,2792,2795,2796,2678,2672,2669,2670,2688,2328,5678,6541,6542,6543,6544,6545,1987,1991,1992,
1993,1994,1995,1996,1997,3939,5927,5950,1988,1998,1999,2000,2001,2002,2003,2004,2365,3940,3960,5926,5949,1947,1948,1949,2120,
2550,2553,2554,2580,2420,5710,5015,5801,5865,5875,5876,5877,5878,5879,5880,5881,5882,5883,5884,5885,5886,5887,5888,5889,5890,
5891,5892,5893,5894,5895,5896,5897,5898,5899,5900,5901,5902,5903,5904,5905,5906,5919,5920,5921,5922,5923,5924,5925,5930,5939,
5946,5947,5948,5952,5954,6093,6105,6106,6107,6095,6096,6097,6098,6099,6100,6101,6102,6528,6531,6566,6567,6568,5080,5097,5480,
5791,5792,5804,5808,5809,5810,5907,5908,2798}
local PRESENT_STORAGE = 5463 -- storage ID.
local SEG = 86400 -- Tiempo que debe esperar el jugador.
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, 'present') then
if os.time() > getPlayerStorageValue(cid,PRESENT_STORAGE) then
selfSay('Do you want to buy a present for 5000 gold?', cid)
talkState[talkUser] = 1
else
selfSay('Come back later for a new present.', cid)
end
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
if doPlayerRemoveMoney(cid, 5000) then
selfSay('Here you are.', cid)
doPlayerAddItem(cid, random_items[math.random(#random_items)], 1)
setPlayerStorageValue(cid, PRESENT_STORAGE, (os.time() + SEG))
if math.random(1, 5) == 1 then
local m = 5000 * math.random(1.5)
doPlayerAddMoney(cid, m)
selfSay('It\'s your lucky day, you received '..m..' gold aswell.', cid)
end
else
selfSay('You don\'t have 5000 gold!', cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Alright!', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())