-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNpcPlayed.lua
More file actions
70 lines (65 loc) · 2.62 KB
/
Copy pathNpcPlayed.lua
File metadata and controls
70 lines (65 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
local NPC = 101040
local function round(number)
if (number - (number % 0.1)) - (number - (number % 1)) < 0.5 then
number = number - (number % 1)
else
number = (number - (number % 1)) + 1
end
return number
end
local function OnGossipHello(event, player, object, unit)
player:GossipClearMenu();
local Query = WorldDBQuery("SELECT * FROM npc_played");
if(Query)then
repeat
local id = Query:GetUInt32(0);
local time = Query:GetUInt32(1);
if(time <= 86400)then
timeplayed = round(Query:GetUInt32(1)/3600).." heures";
else
timeplayed = round(Query:GetUInt32(1)/86400).." jours";
end
player:GossipMenuAddItem(0, "Temps de jeu requis: "..timeplayed, 1, id, false, "Soyez certains d'avoir de la place dans vos sacs avant de cliquer sur 'Accepter'.");
until not Query:NextRow()
end
player:GossipMenuAddItem(0, "Partir...", 1, 999);
player:GossipSetText("Bonjour, vous êtes venu récuperer vos récompenses de temps de jeu ?");
player:GossipSendMenu(0x7FFFFFFF, object, MenuId)
end
local function OnGossipSelect(event, player, creature, sender, intid, code)
local pGuid = player:GetGUIDLow();
local pPlayed = player:GetTotalPlayedTime();
if(intid == 999)then
player:GossipComplete();
else
local QueryCheck = CharDBQuery("SELECT guid FROM character_played_reward WHERE rewardid = "..intid.." AND guid = "..pGuid..";");
if(QueryCheck)then
player:GossipComplete();
player:SendAreaTriggerMessage("Vous avez déjà récuperé cette récompense...");
else
local QueryGive = WorldDBQuery("SELECT item_1, item_amount_1, item_2, item_amount_2, item_3, item_amount_3, seconds FROM npc_played WHERE id = "..intid..";");
local item1 = QueryGive:GetUInt32(0);
local aitem1 = QueryGive:GetUInt32(1);
local item2 = QueryGive:GetUInt32(2);
local aitem2 = QueryGive:GetUInt32(3);
local item3 = QueryGive:GetUInt32(4);
local aitem3 = QueryGive:GetUInt32(5);
local musthavetime = QueryGive:GetUInt32(6);
if(musthavetime <= pPlayed)then
player:AddItem(item1, aitem1);
player:AddItem(item2, aitem2);
player:AddItem(item3, aitem3);
local QueryUpdate = CharDBExecute("INSERT INTO character_played_reward(guid, rewardid) VALUES("..pGuid..","..intid..");");
player:SendAreaTriggerMessage("Voila vos objets !");
player:GossipComplete();
else
player:SendAreaTriggerMessage("Vous n'avez pas assez joué pour recevoir cette récompense...");
end
end
player:GossipComplete();
end
end
RegisterCreatureGossipEvent( NPC, 1, OnGossipHello )
RegisterCreatureGossipEvent( NPC, 2, OnGossipSelect )
local console = debug.getinfo (1, "S").short_src;
print("- "..console);