Jump to content

Trigger when the player isn't new.


Recommended Posts

  • Moderators

If I start my script it will trigger to server side, to check if the player is login. What is the best way to check if the player did not just joined.

This one must only be triggered(to server side) when the player is already in game. (client)

  
addEventHandler( "onClientResourceStart", resourceRoot, 
function () 
    triggerServerEvent("clientLoaded",localPlayer) 
end) 

Link to comment
What is the best way to check if the player did not just joined.

I didn't understand that at all xD

https://wiki.multitheftauto.com/wiki/IsTransferBoxActive

Maybe I didn't understood you at all but maybe is this something:?

function dl() 
if (isTransferBoxActive() == false) then 
triggerServerEvent("clientLoaded",localPlayer) 
else 
if ( isTimer( chektimer ) ) then --just incase  
killTimer ( chektimer ) 
end 
end 
end 
  
addEventHandler( "onClientResourceStart", resourceRoot, 
function () 
chektimer = setTimer(dl, 2000, 0) 
end) 

You want to chek if the player is logged in or so from the client?

or do you want to chek if the player has logged in but not the people who are joined?

Can you tell it me maybe what you trying to do?

Link to comment
  • Moderators

Well as sample:

There 3 players in-game and 1 player is going to join.

When I start the resource, the 3 players are triggering to serverside.

Next the other player joins the server and he triggered too. <-- and this is what I want to be prevent from happening.

I tried to use getTickCount(), to get:

This function returns amount of time that your system has been running in milliseconds. By comparing two values of getTickCount, you can determine how much time has passed (in milliseconds) between two events. This could be used to determine how efficient your code is, or to time how long a player takes to complete a task.  

But some how the tickcount is already changing after I started mta or when I reconnect to the server. (so I can't check if this player is new or already in game)

ElementData isn't a solution, this script probably triggerd faster then the elementData reached the player who is downloading, next to that is is laggy, because all new client players have to download each other status.

NL: Ik wil gewoon weten of de speler nieuw is of al in game is, so dat ik kan bepalen of ik het wil sturen of niet.

Link to comment

-- Client Side --

addEventHandler("onClientResourceStart", resourceRoot, 
function() 
    if getElementData(localPlayer, "Whatever") then 
        triggerServerEvent("clientLoaded", localPlayer) 
    end 
end) 

-- Server Side --

addEventHandler("onResourceStart", resourceRoot, 
function() 
    for i, player in ipairs (getElementsByType("player")) do 
        setElementData(player, "Whatever", true) 
    end 
end) 

Link to comment
aha

well it may will work, but one trigger is something you can't compare with: elementdata*playerCount

Thx anyway guys.

You don't want use elementdata?

Well another way, let everyone do the trigger and in the same time in server side put all players in the server in a table and when the trigger come from the client check if the source of the trigger was in the table or not.

Link to comment
  • Moderators

ah yes, but then I am sending this trigger.

It doesn't really matter if it have been send, it was more meant to save data travel by preventing the trigger.

Well it is just a trigger... but it is handy to know if there is a possibility to find a way to do this on client side, without using any extra bandwidth.

Link to comment

Use variables on the server side...

For example:

  
local canjoin = true 
  
addEventHandler( "onPlayerJoin", root, -- or onPlayerLogin 
function () 
    if ( canjoin == false ) then 
            outputChatBox ( "You can't join the spy-vs-spy game, spectator mode started.", source, 255,0,0, true ) 
        elseif ( canjoin == true ) then 
            outputChatBox ( "You joined the spy-vs-spy game!", source, 255,0,0, true ) 
    end 
end) 

And then you should edit your system ;p

It's the fasted way.

edit: or contact me on skype xD

edit2:

If you want to get it on the client side you need to store the data in a table, and then trigger the tabledata to the client, but I prefer server side.

edit3(0.o):Why do you actaully want this on your new gamemode xD, it's just funnier to play direct instead of waiting..

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...