PDA

View Full Version : [SOLVED] 2.4.3 Race Change Script



Grim
07-19-2016, 04:29 AM
Hello,

I've been using this forum for a while now along my brother and still haven't made an account :embarassed: Anyways, him and I attempted to code a Race/Faction changer. It seems that it doesn't execute the actual SQL Query or if it does when the player gets kicked, it gets overridden?
We have been stumped for quite a while about this and would like any assistance at all :smile:

--[[

Race Change Script
Developed for CMaNGOS 2.4.3

Developers: Grim, Render1982

]]


local NPC_ENTRY = 60010

function ChangeRaceMenu(event, player, unit)
if player:GetGender() == 0 then
player:GossipMenuAddItem(0, "Change Race to Orc", 0, 1)
-- else
-- player:GossipMenuAddItem(0, "Change Race to Human", 0, 2)
end
player:GossipMenuAddItem(0, "Nevermind..", 0, 3)
player:GossipSendMenu(1, unit)
end

function ChangeRaceSelect(event, player, unit, sender, intid, code)
if (intid == 1) then
player:KickPlayer()
CharDBQuery("UPDATE `characters`.`characters` SET `race`=2 WHERE `guid`="..player:GetGUIDLow()..";")
-- elseif (intid == 2) then

-- elseif (intid == 3) then

end
end


RegisterCreatureGossipEvent(NPC_ENTRY, 1, ChangeRaceMenu)
RegisterCreatureGossipEvent(NPC_ENTRY, 2, ChangeRaceSelect)

EDIT: If the GUID is set to default value other than the current player's GUID it works without a flaw. Might've also wanted to pointed that out

Tommy
07-19-2016, 06:15 AM
Why not tell the player to relog in a message instead of kicking them? The logic behind that script is that you are kicking the player before you run the query, so I don't think it will work like that since the player is no longer in the world when you are trying to use the player variable. You could probably create a timed event and when the query executes then kick the player.

Syphex
07-19-2016, 12:16 PM
As Tommy said, tell the player to relog, i find nothing worse than being forced of the server rather than willingly.
Look at it from the bright side, when blizzard did race,faction changes etc back in the days you even had to log out from your account for the changes and updates to work.

Grim
07-19-2016, 02:19 PM
--[[

Race Change Script
Developed for CMaNGOS 2.4.3

Developers: Grim, Render1982

]]


local NPC_ENTRY = 60010

function ChangeRaceMenu(event, player, unit)
if player:GetGender() == 0 then
player:GossipMenuAddItem(0, "Change Race to Orc", 0, 1)
-- else
-- player:GossipMenuAddItem(0, "Change Race to Human", 0, 2)
end
player:GossipMenuAddItem(0, "Nevermind..", 0, 3)
player:GossipSendMenu(1, unit)
end

function ChangeRaceSelect(event, player, unit, sender, intid, code)
if (intid == 1) then
local pGUID = player:GetGUIDLow()
CharDBQuery("UPDATE `characters`.`characters` SET `race`=2 WHERE `guid`="..pGUID..";")
player:SendBroadcastMessage("|cFFFFA500Please Relog!")
-- elseif (intid == 2) then

-- elseif (intid == 3) then

end
end


RegisterCreatureGossipEvent(NPC_ENTRY, 1, ChangeRaceMenu)
RegisterCreatureGossipEvent(NPC_ENTRY, 2, ChangeRaceSelect)

Still doesn't do anything. I think the problem was relogging cause it may be querying it then when the player logs out it saves the char to the DB which may override it.
It simply just say "Please Relog" and when you do actually relog nothing happens.

Tommy
07-19-2016, 05:16 PM
--[[

Race Change Script
Developed for CMaNGOS 2.4.3

Developers: Grim, Render1982

]]


local NPC_ENTRY = 60010

function ChangeRaceMenu(event, player, unit)
if player:GetGender() == 0 then
player:GossipMenuAddItem(0, "Change Race to Orc", 0, 1)
-- else
-- player:GossipMenuAddItem(0, "Change Race to Human", 0, 2)
end
player:GossipMenuAddItem(0, "Nevermind..", 0, 3)
player:GossipSendMenu(1, unit)
end

function ChangeRaceSelect(event, player, unit, sender, intid, code)
if (intid == 1) then
local pGUID = player:GetGUIDLow()
CharDBQuery("UPDATE `characters`.`characters` SET `race`=2 WHERE `guid`="..pGUID..";")
player:SendBroadcastMessage("|cFFFFA500Please Relog!")
-- elseif (intid == 2) then

-- elseif (intid == 3) then

end
end


RegisterCreatureGossipEvent(NPC_ENTRY, 1, ChangeRaceMenu)
RegisterCreatureGossipEvent(NPC_ENTRY, 2, ChangeRaceSelect)

Still doesn't do anything. I think the problem was relogging cause it may be querying it then when the player logs out it saves the char to the DB which may override it.
It simply just say "Please Relog" and when you do actually relog nothing happens.

Yeah, you'd have to probably give the player the race change flag. Not sure if you are wanting to do only Orc and Human race change which will make the race change flag pointless since you can change to any race you want.

Jpp
07-19-2016, 06:03 PM
Just store the GUID in a variable before kicking the player and then use it in the query.

If you plan on using all races and giving them the ability to customize the change, just give them the race change flag instead.

Grim
07-19-2016, 08:15 PM
So I added this line under the NPC entry variable and still got nothing.:loco:

And this is patch 2.4.3 so the race change flag doesn't exist...yet.

I did the orc and human as a test I'ma add the rest of races with a class check so people can't make Orc Paladins :loco: but, right now I'm just wanting to make it at least work with the script I got.

Foereaper
07-19-2016, 08:38 PM
But the player save query isn't async on logout is it? If it isn't you could store the guid on logout and then run a timed event.

Edit:

Yeah, just checked. The saving is only done while the player is still in the world. It should allow you to use a timed event after the player has actually logged out then.

Grim
07-20-2016, 03:46 AM
Yep, the timed event works and it now works flawlessly! Thanks all for helping. I posted it in the Releases as a thanks to the community :smile::smile: