SoManyTears

is setElementInterior not used in onPlayerLogin event? or whats problem ?

Recommended Posts

it works when I use this event as onPlayerWasted.but the player does not teleport while login.am i using a wrong event?

local warps = {
{ 2,2577.3100585938, -1329.7434082031, 1058.2553710938 },
{ 2,2573.6740722656, -1353.0935058594, 1058.2553710938 },
{ 2,2581.5959472656, -1343.3308105469, 1054.0562744141 }
} 

addEventHandler( "onPlayerLogin", getRootElement( ),
function()
local rnd = math.random( 1, #warps ) 
 local level = getPlayerWantedLevel ( source )
 if ( level == 1 ) then 
setPedWeaponSlot ( source, 0 )
fadeCamera(source,false, 1.0)
setTimer(fadeCamera, 1000, 1,source,true)
setTimer ( setElementInterior, 1000, 1, source, warps[rnd][1], warps[rnd][2], warps[rnd][3], warps[rnd][4], warps[rnd][5], warps[rnd][6], warps[rnd][7], warps[rnd][8] )
triggerClientEvent(source, "jailTime1", source)

        setTimer(function(freeman)
                if isElement(freeman) then
				fadeCamera(freeman,false, 1.0)
setTimer(fadeCamera, 1000, 1,freeman,true)
setTimer (setElementPosition, 1000, 1, freeman, 1803.2666015625, -1575.6591796875, 13.408905029297 )  
setElementInterior ( freeman, 0 )
setPlayerWantedLevel ( freeman, 0 )
				end     
        end,1000*20,1,source)
	end
	end
)

 

Share this post


Link to post
Posted (edited)
45 minutes ago, SoManyTears said:

it works when I use this event as onPlayerWasted.but the player does not teleport while login.am i using a wrong event?

Hello SoManyTears,

I was unable to find any substantial issue in your script so I tried it on my local server and it worked. Here are my questions:

  • have you set a server-side wanted level for your player element? if you set a client-side wanted level then this server-side script will not trigger
  • have you logged in while having a wanted level of 1? If you have logged in prior to that then you will not be teleported

The teleport is weird tho. Maybe because I don't have the entire resource. I got teleported somewhere into the air with no solid ground underneath my feet ;) 

You can use the following runcode command to help you debug this script:

run setPlayerWantedLevel(getPlayerFromName("SoManyTears"), 1)

 

Edited by The_GTA

Share this post


Link to post

Hello The-GTA !

I used setAccountData to save wanted levels and succeeded.I give myself a star from execute commands.I enter the game, I have a star, but I am not teleported anywhere :(I really don't know what the problem is.my resource will be ready when i solve this problem: /

There is a map where I teleport.you will go into the SKY when you are teleported. :D

Share this post


Link to post
1 minute ago, SoManyTears said:

Hello The-GTA !

I used setAccountData to save wanted levels and succeeded.I give myself a star from execute commands.I enter the game, I have a star, but I am not teleported anywhere :(I really don't know what the problem is.my resource will be ready when i solve this problem: /

There is a map where I teleport.you will go into the SKY when you are teleported. :D

So you have mentioned that you have maybe used the wrong event here. I think you have assumed partially right because you want to set wanted levels using account data but this data is only available after login. So if you set wanted level data after player logged in he will never be teleported.

What you are missing is another event handler when you set the wanted level. After you set the wanted level you must execute the same code you posted above. I recommend that you turn the event handler into a separate named local function and use it in both cases :)

If you share your complete code we could assist you in implementing that.

Share this post


Link to post
Posted (edited)

then I explain the logic in me.I created a simple wanted level save with SetAccountData.I'm really new to Lua and couldn't do any other save system.ı did it :

function onQuit() 
    local acc = getPlayerAccount(source) 
    if not isGuestAccount(acc) then 
        local wantedLevel = getPlayerWantedLevel (source) 
        setAccountData(acc, "wlevel", wantedLevel)		
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onQuit) 
  
function onLogin(_, acc) 
    local acc = getPlayerAccount(source)
    local wantedLevel = getAccountData(acc, "wlevel") 
    setTimer (setPlayerWantedLevel,500,1,source,wantedLevel)	
end 
addEventHandler("onPlayerLogin", getRootElement(), onLogin)
and I created a logic.If this player has a star, I wrote a code to teleport him to jail.and I didnt write codes for every star, because I don't know how to make a table right now.Anyway I can edit this in the future.these are all the codes i have and i can't get results.Maybe it is easy for you but I wrote something as much as I know about Lua and it is negative ...
Edited by SoManyTears

Share this post


Link to post
38 minutes ago, SoManyTears said:

then I explain the logic in me.I created a simple wanted level save with SetAccountData.I'm really new to Lua and couldn't do any other save system.ı did it :

and I created a logic.If this player has a star, I wrote a code to teleport him to jail.and I didnt write codes for every star, because I don't know how to make a table right now.Anyway I can edit this in the future.these are all the codes i have and i can't get results.Maybe it is easy for you but I wrote something as much as I know about Lua and it is negative ...

I have extended and fixed your script according to my points I posted above. There are comments in the script to help you explain. Please take your time to read the comments and learn from the code because it is well made and you should always follow these guidelines when creating server system scripts (like account systems):

-- Warp points for jails.
local warps = {
    { 2,2577.3100585938, -1329.7434082031, 1058.2553710938 },
    { 2,2573.6740722656, -1353.0935058594, 1058.2553710938 },
    { 2,2581.5959472656, -1343.3308105469, 1054.0562744141 }
} 

-- Do the actual jailing.
local function onPlayerWantedLevelChange(source, level)
    local acc = getPlayerAccount(source);
    if (isGuestAccount(acc)) then return; end;
    
    local rnd = math.random( 1, #warps ) 
    if ( level == 1 ) then 
        setPedWeaponSlot ( source, 0 )
        fadeCamera(source,false, 1.0)
        setTimer(fadeCamera, 1000, 1,source,true)
        setTimer ( setElementInterior, 1000, 1, source, warps[rnd][1], warps[rnd][2], warps[rnd][3], warps[rnd][4], warps[rnd][5], warps[rnd][6], warps[rnd][7], warps[rnd][8] )
        triggerClientEvent(source, "jailTime1", source)
        
        setTimer(
            function(freeman)
                if isElement(freeman) then
                fadeCamera(freeman,false, 1.0)
                setTimer(fadeCamera, 1000, 1,freeman,true)
                setTimer (setElementPosition, 1000, 1, freeman, 1803.2666015625, -1575.6591796875, 13.408905029297 )  
                setElementInterior ( freeman, 0 )
                updatePlayerWantedLevel ( freeman, 0 )
                end
            end,1000*20,1,source)
    end
end

-- Use this function always if you want to set wanted level.
function updatePlayerWantedLevel(player, level)
    -- Uncomment this if you want to jail only players that have a change in wanted level.
    --if (getPlayerWantedLevel(player) == level) then return true; end;

    local success = setPlayerWantedLevel(player, level);
    
    if not (success) then return false; end;
    
    onPlayerWantedLevelChange(player, level);
    return true;
end

-- Save jail system variables.
local function savePlayerAccount(player, account)
    local wantedLevel = getPlayerWantedLevel (player)
    setAccountData(account, "wlevel", wantedLevel)		
    -- Uncomment this if you want to clean up wanted level on save.
    --setPlayerWantedLevel(player, 0)
end

-- Set wanted level to player that we remember in his account.
local function loadPlayerAccount(player, acc)
    local wantedLevel = getAccountData(acc, "wlevel") 
    setTimer (updatePlayerWantedLevel,500,1,player,wantedLevel)	
end

-- Remember jail system variables if player logs out.
local function onPlayerLogout(account)
    savePlayerAccount(source, account);
end
addEventHandler("onPlayerLogout", root, onPlayerLogout);

-- Remember jail system variables if player leaves the server.
local function onQuit() 
    local acc = getPlayerAccount(source) 
    if not isGuestAccount(acc) then 
        savePlayerAccount(source, acc);
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onQuit) 

-- Jail players that log in.
local function onLogin(_, acc) 
    local acc = getPlayerAccount(source)
    loadPlayerAccount(source, acc);
end 
addEventHandler("onPlayerLogin", getRootElement(), onLogin)

-- Remember the jail system variables if resource stops.
local function onResourceStop()
    for m,n in ipairs(getElementsByType("player")) do
        local acc = getPlayerAccount(n);
        
        if not (isGuestAccount(acc)) then
            savePlayerAccount(n, acc);
        end
    end
end
addEventHandler("onResourceStop", resourceRoot, onResourceStop, false);

-- Jail all players that are on server when resource starts up.
local function onResourceStart()
    for m,n in ipairs(getElementsByType("player")) do
        local acc = getPlayerAccount(n);
        
        if not (isGuestAccount(acc)) then
            loadPlayerAccount(n, acc);
        end
    end
end
onResourceStart();

Feel free to ask any questions about it :) 

  • Thanks 1

Share this post


Link to post

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.