• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Help with Script Lua

kusanagy

Respected Member
Hi guys,
wanted to help me with this script, its function is to promote, and I want this script, detects that it has already delivered according promotion account = id of characters.
How can i fix this.

always continues to promote them all.

Code:
function NPClevel_Gossip(event, player, unit)
		if (player:IsInCombat() == true) then
			else
			NPClevel_Menu(unit, player)
		end
end

function NPClevel_Menu(unit, player)
player:GossipMenuAddItem(4, "|Tinterface/icons/Ability_Mage_LivingBomb:20:20:-13:0|tPromo Nivel 80", 0, 1)
player:GossipMenuAddItem(4, "|Tinterface/icons/Ability_Vehicle_LoadSelfCatapult:20:20:-13:0|tnevermind", 0 , 9)
player:GossipSendMenu(1, unit)
end

function NPClevel_Events(event, player, unit, sender, intid, code)
if (intid == 1) then
local playerGUID = player:GetAccountId()
local result = CharDBQuery("SELECT COUNT(`guid`) FROM characters WHERE account = "..playerGUID)
if (result) then
		player:SetLevel(80)
		player:SendBroadcastMessage("Congratulations you won the Promotion, one character per account!")
		if (player:GetLevel() == 80) then
		player:GossipComplete()
		end
	else
		player:PlayDirectSound(1807)
		player:SendNotification("you already have this promotion!")
		player:GossipComplete()
	end
end

if (intid == 9) then
player:GossipComplete()
end
end
 

Tommy

Founder
Well you have no real definitive checks to check if you already promoted. Imo you could add a new column in one of your tables (e.g. tinyint ~ 1 for already promoted and 0 for not) then check it within the code. Your "else" code is somewhat irrelevant because if it doesn't find a result it will give false information to the player. That code should be within your "already promoted" check.
 

MrPixelMC

Member
I don't know much about Eluna but are you sure that's the query you want to run?
A SELECT COUNT will always have a result (it will return 0 if not found).
Also I wouldn't name the variable that holds the account ID "playerGUID", it's kinda misleading!
 
Top