Jump to content

help with getAccountData


Recommended Posts

function spawnpanel()
local acc = getPlayerAccount(source)
if getAccountData(acc, "FirstLoginKek", false) then
triggerClientEvent(acc, "spawnpanel")
setAccountData(acc, "FirstLoginKek", true)
outputChatBox("works", acc, 255, 0, 0)
end
end
addEventHandler("onPlayerLogin", getRootElement(), spawnpanel)

In this code, when players join the server for the first time, they get a message with ''works''. Their account data will be set to ''FirstLoginKek'', so if they join again, they won't see the message anymore. So I tried this in my server, I did not have the accountdata, but it didn't work. The ClientEvent didn't work, and the output didn't show up. This is the first time I work with getAccountData, so I'm not sure if this is the way to use it, but yeah help would be greatly appreciated.

Edited by marty000123
Link to comment
function spawnpanel()
    local acc = getPlayerAccount(source)
    if getAccountData(acc, "FirstLoginKek") == false then --wrong syntax
        triggerClientEvent(acc, "spawnpanel")
        setAccountData(acc, "FirstLoginKek", true)
        outputChatBox("works", acc, 255, 0, 0)
    end
end
addEventHandler("onPlayerLogin", getRootElement(), spawnpanel)

You can use either:

If getAccountData(account,"key") == false then

Or

If not getAccountData (account,"key") then

Link to comment
  • Moderators

That depends if the variable `green` is available and if the `team` is the team name. You can't save elements inside accountdata, teams are elements.

 

teamName = "green"  -- getTeamName ( team theTeam )// https://wiki.multitheftauto.com/wiki/GetTeamName

setAccountData(acc, "team", teamName)

if getAccountData(acc, "team") == teamName then

 

Link to comment
11 minutes ago, IIYAMA said:

That depends if the variable `green` is available and if the `team` is the team name. You can't save elements inside accountdata, teams are elements.

 


teamName = "green"  -- getTeamName ( team theTeam )// https://wiki.multitheftauto.com/wiki/GetTeamName

setAccountData(acc, "team", teamName)

if getAccountData(acc, "team") == teamName then

 

Alright, thanks.

Edited by marty000123
Link to comment
  • Moderators
local allTeamData = {
	["Ghost Mercenaries"] = {
		spawnpoint = {-176.84535, 996.75055, 23.63281, 180, 287, 0}
		-- add more data if you want.
	},
	["Special Military Unit"] = {
		spawnpoint = {-176.84535, 996.75055, 23.63281, 180, 287, 0}
		-- add more data if you want.
	},
	["People's Protection Power"] = {
		spawnpoint = {-176.84535, 996.75055, 23.63281, 180, 287, 0}
		-- add more data if you want.
	}
}

function onDeath()
	-- get the player his account
	local acc = getPlayerAccount(source)
	
	-- is played logged in?
	if not isGuestAccount(acc) then 
	
		local teamName = getAccountData(acc, "team")
		local teamData = allTeamData[teamName] -- get the data based on the teamName
		if teamData then
			local teamElement = getTeamFromName(teamName)
			if teamElement then
				setPlayerTeam(source, teamElement)
				spawnPlayer (source, unpack(teamData.spawnpoint))
			else
				outputDebugString("<" .. tostring(getPlayerName(source)) .. "> " .. "can't find team")
			end
		else
			outputDebugString("<" .. tostring(getPlayerName(source)) .. "> " .. "team doesn't have teamData!")
		end
	else
		outputDebugString("<" .. tostring(getPlayerName(source)) .. "> " .. "player isn't logged in")
	end
end
addEventHandler("onPlayerWasted", root, onDeath)

 

Link to comment
38 minutes ago, IIYAMA said:

 

Thanks for the help, but I think I came up with something else. However, that thing isn't working while it should. Can you guys check it?

function spawnAfterLogInOrDeath()
local acc = getPlayerAccount(source)
if getAccountData(acc, "FirstLoginNow") == true then
setTimer(
function()
if getAccountData(acc, "green") == true then
setPlayerTeam(player, getTeamFromName("Special Military Unit"))
spawnPlayer (player, -176.84535, 996.75055, 23.63281, 180, 287, 0)
end
if getAccountData(acc, "blue") == true then
setPlayerTeam(player, getTeamFromName("People's Protection Power"))
spawnPlayer (player, -176.84535, 996.75055, 23.63281, 180, 282, 0)
end
if getAccountData(acc, "red") == true then
setPlayerTeam(player, getTeamFromName("Ghost Mercenaries"))
spawnPlayer (player, -176.84535, 996.75055, 23.63281, 180, 285, 0)
end
end, 3000, 1)
end
end
addEventHandler("onPlayerLogin", getRootElement(), spawnAfterLogInOrDeath)
addEventHandler("onPlayerWasted", getRootElement(), spawnAfterLogInOrDeath)

It says ''bad argument @ spawnplayer AND setPlayerTeam (expected player at argument 1, got nil)'' I tried player, thePlayer and source, yet nothing worked.

Edited by marty000123
Link to comment
34 minutes ago, marty000123 said:

Thanks for the help, but I think I came up with something else. However, that thing isn't working while it should. Can you guys check it?

It says ''bad argument @ spawnplayer AND setPlayerTeam (expected player at argument 1, got nil)'' I tried player, thePlayer and source, yet nothing worked.

function spawnAfterLogInOrDeath(player)

+
split the events don't make it in the same functions

Edited by 3laa33
Link to comment
26 minutes ago, 3laa33 said:

function spawnAfterLogInOrDeath(player)

+
split the events don't make it in the same functions

This is what I got now:

function spawnAfterDeathOrLogin(player)
local acc = getPlayerAccount(source)
if getAccountData(acc, "FirstLoginNow") == true then
setTimer(
function()
if getAccountData(acc, "green") == true then
setPlayerTeam(player, getTeamFromName("Special Military Unit"))
spawnPlayer (player, 235.47963, 1872.47766, 11.46094, 180, 287, 0)
triggerClientEvent("class", player)
end
if getAccountData(acc, "blue") == true then
setPlayerTeam(player, getTeamFromName("People's Protection Power"))
spawnPlayer (player, -176.84535, 996.75055, 23.63281, 180, 282, 0)
triggerClientEvent("class", player)
end
if getAccountData(acc, "red") == true then
setPlayerTeam(player, getTeamFromName("Ghost Mercenaries"))
spawnPlayer (player, -551.11359, 2593.78394, 53.93478, 180, 285, 0)
triggerClientEvent("class", player)
end
end, 3000, 1)
end
end
addEventHandler("onPlayerWasted", getRootElement(), spawnAfterDeathOrLogin)
addEventHandler("onPlayerLogin", getRootElement(), spawnAfterDeathOrLogin)

It still doesn't work. It gives another warning now: bad argument @ spawnPlayer AND setPlayerTeam AND triggerClientEvent (expected player at argument 1 (or 2), got number '1')

Edited by marty000123
Link to comment
14 minutes ago, 3laa33 said:

show me

Trust me, I did exactly that and it didnt work. (i split the script into 6, 3 colors when you die and 3 colors when you login, same elements)

Now for some reason the warning changed to: ad argument @ spawnPlayer AND setPlayerTeam AND triggerClientEvent (expected player at argument 1 (or 2), got number '42')

So instead of ''1'', it shows ''42'' meaning that the number changes, why I don't know. Not sure why it doesn't just pick player.

Edited by marty000123
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...