Jump to content

[Help] getplayeraccount got ped error


SinaAmp

Recommended Posts

Hello guys

i want to get player account to save his name in database but i got this error:

accerror_tec9.png

script:

function BuySkin159 (theplayer)
	local account = getPlayerAccount(theplayer)
	local accName = getAccountName(account)
	local skinprice = 5000
	if account then
		if getPlayerMoney(theplayer) >= skinprice then
			takePlayerMoney(theplayer, 5000)
			setTimer(function()
			fadeCamera(theplayer,true)
			setElementModel(theplayer, 159)
			local ID = getFreeID()
			local skinid = 159
			local myData = dbExec(db,"INSERT INTO SkinShop VALUES (?, ?, ?)",ID,accName,skinid)
			skin = getElementModel(theplayer)
			outputChatBox("#00ff00 [Done]: #ffffffskin shoma be id #ff0000"..skin.."#ffffff taghir kard",theplayer, 255,255,255,true)
		end,1000,1)
		fadeCamera(theplayer,false)
	end
	end
end
addEventHandler("onMarkerHit", marker1, BuySkin159)

 

Edited by SinaAmp
Link to comment
I think here it gives a warning message because something other than the player element enters the marker.

You can check it with getElementType

function BuySkin159 (theplayer)
	if(getElementType(theplayer) ~= "player") then return end -- if theplayer not player stop continue
	local account = getPlayerAccount(theplayer)
    local skinprice = 5000
	if(account) then -- Does the player have an account?
       if(isGuestAccount(account)) then return end -- if account guest account stop continue
       local accName = getAccountName(account)
       if getPlayerMoney(theplayer) >= skinprice then
            takePlayerMoney(theplayer, 5000)
			setTimer(function()
			fadeCamera(theplayer,true)
			setElementModel(theplayer, 159)
			local ID = getFreeID()
			local skinid = 159
			local myData = dbExec(db,"INSERT INTO SkinShop VALUES (?, ?, ?)",ID,accName,skinid)
			skin = getElementModel(theplayer)
			outputChatBox("#00ff00 [Done]: #ffffffskin shoma be id #ff0000"..skin.."#ffffff taghir kard",theplayer, 255,255,255,true)
		    end,1000,1)
		    fadeCamera(theplayer,false)
       end

	end
end
addEventHandler("onMarkerHit", marker1, BuySkin159)
Edited by Burak5312
  • Thanks 1
Link to comment

Thank you bro problem solved

i want to wrote the script that get skin id from database after login and set player model to it

but again my script not work:

function afterlogin()
	local skinData = dbQuery(db,"SELECT Skin,Account FROM SkinShop")
	local result = dbPoll(skinData,-1)
	if (result) and (result[1]) and (result[2]) then
		
		setElementModel(source, result[1].skin )
		
	end
end
addEventHandler("onPlayerLogin",root, afterlogin)

 

Link to comment
2 minutes ago, SinaAmp said:

Thank you bro problem solved

i want to wrote the script that get skin id from database after login and set player model to it

but again my script not work:

function afterlogin()
	local skinData = dbQuery(db,"SELECT Skin,Account FROM SkinShop")
	local result = dbPoll(skinData,-1)
	if (result) and (result[1]) and (result[2]) then
		
		setElementModel(source, result[1].skin )
		
	end
end
addEventHandler("onPlayerLogin",root, afterlogin)

 

Can you show the data coming with outputDebugString

outputDebugString(result[1].skin)

 

Link to comment

hmm maybe try changing "skin" to "Skin"?

function afterlogin()
	local skinData = dbQuery(db,"SELECT Skin,Account FROM SkinShop")
	local result = dbPoll(skinData,-1)
	if (result) and (result[1]) and (result[2]) then
		
		setElementModel(source, result[1].Skin )
		
	end
end
addEventHandler("onPlayerLogin",root, afterlogin)
Edited by Burak5312
Link to comment

finally solved this issue

function afterlogin(theplayer)
	if isElement(theplayer) and getElementType(theplayer) ~= "player" then return end
	local SkinData = dbPoll(dbQuery(db,"SELECT Account,Skin,ID FROM SkinShop"), -1)
	local account = getPlayerAccount(source)
	local accName = getAccountName(account)
	if (SkinData) and (SkinData[1]) and (SkinData[2]) then
		if (SkinData[1].Account == tostring(accName)) then
		setElementModel(source, SkinData[2].Skin )
		end
	end
end
addEventHandler("onPlayerLogin",root, afterlogin)

 

Link to comment

actually you don't need some lines here like getPlayerAccount because the onPlayerLogin event carries the account you are logged into so change it like this

function afterlogin(_,account) -- this account
	local SkinData = dbPoll(dbQuery(db,"SELECT Account,Skin,ID FROM SkinShop"), -1)
	--local account = getPlayerAccount(source) -- no need this
	local accName = getAccountName(account)
	if (SkinData) and (SkinData[1]) and (SkinData[2]) then
		if (SkinData[1].Account == tostring(accName)) then
		setElementModel(source, SkinData[2].Skin )
		end
	end
end
addEventHandler("onPlayerLogin",root, afterlogin)

 

Edited by Burak5312
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...