Jump to content

Tables + client side + server side + spawn


DarkLink

Recommended Posts

Okay look guys, I have been trying to do something, but its not working .

So I have a gui on client side (ofc) players choose their team, and their client info will be saved, so later they will all spawn.

I have these on client side when they choose team , I mean when they click the button of the team:

client :

  
function chooseTeam(button,state) 
    -- if our login button was clicked with the left mouse button, and the state of the mouse button is up 
    if button == "left" and state == "up" then 
        -- move the input focus back onto the game (allowing players to move around, open the chatbox, etc) 
        if source == btnIMI then 
            equipa = "imigrante" 
        else 
            equipa = "police" 
        end 
         
        triggerServerEvent("buttonClicked", getRootElement(), equipa, client) 
        guiSetInputEnabled(false) 
        -- hide the window and all the components 
        guiSetVisible(wdwLogin, false) 
        -- hide the mouse cursor 
        showCursor(false) 
    end 
end 
  

and on the server side I have these:

  
playersForIMI = {} 
playersForPOL = {} 
  
function joinHandler(equipa, client) 
    if (gamemodeStarted == false) then 
     
     
         
        if(equipa == 'imigrante') then 
            table.insert(playersForIMI, client) 
        else 
            table.insert(playersForPOL, client) 
        end 
         
         
    end 
     
end 
addEventHandler("buttonClicked", root, joinHandler) 
  

okay the above codes will set the client info ( I mean the player ) on the table, to spawn next .

and then the spawn functions, that will be called after the timer:

on server side the timer:

  
    function countDown() 
        segundos = segundos -1 
            for i,v in pairs(getElementsByType("player")) do 
                setElementData(v,"secondsRemaining",tostring(segundos)) 
            end 
            if segundos <= 0 then 
                triggerClientEvent ( "hideDX", getRootElement() ) 
                timerEnabled = false 
                setTimer(spawn, 50, 1, playersForIMI, playersForPOL) 
                gamemodeStarted = true 
            end 
    end 
  

Like u see when timer go to 0, it will call the spawn function with both tables in arguments.

So here it is, on server side too ofc:

  
function spawn (playersForIMI, playersForPOL)  
  
  
     
     
     
    team_policeSP = getTeamFromName("Police") 
    team_immigrantsSP = getTeamFromName("Emigrants") 
     
    local policeSPtable = getElementsByType('spawnpoint', team_policeSP) 
    local immigrantsSPtable = getElementsByType('spawnpoint', team_immigrantsSP) 
    local nr = math.random ( #policeSPtable ) 
    local spawnPointPolice = policeSPtable[ nr ] 
  
     
    nr = math.random ( #immigrantsSPtable ) 
    local spawnPointImmigrants = immigrantsSPtable [ nr ] 
     
     
     
     
    for i, v in ipairs(playersForIMI) do 
     
        playersOnImmigrants = countPlayersInTeam ( team_immigrantsSP ) 
        playersOnPolice = countPlayersInTeam ( team_policeSP ) 
     
        if (playersOnImmigrants == playersOnPolice or playersOnImmigrants == playersOnPolice -1) then 
         
             
            x, y, z = getElementPosition(spawnPointImmigrants) 
         
            if setPlayerTeam" class="kw6">setPlayerTeam ( playersForIMI[i], team_immigrantsSP ) then 
              
                outputChatBox("You are on immigrants team, ruun!", playersForIMI[i]) 
                 
                for i, v in ipairs(getPlayersInTeam(team_immigrantsSP)) do 
                    createBlipAttachedTo ( playersForIMI[i], 0, 3, 205, 133, 63, 255, 0, 99999.0,  v) 
                end 
                 
                 
                playersOnImmigrants = countPlayersInTeam ( team_immigrantsSP ) 
                playersOnPolice = countPlayersInTeam ( team_policeSP ) 
                outputChatBox("Number of immigrants: " .. playersOnImmigrants, playersForIMI[i]) 
                outputChatBox("Number of polices: " .. playersOnPolice, playersForIMI[i]) 
                 
                spawnPlayer(playersForIMI[i], x, y, z) 
                fadeCamera(playersForIMI[i], true) 
                setCameraTarget(playersForIMI[i], playersForIMI[i]) 
                outputChatBox("Welcome to My Server", playersForIMI[i]) 
                 
            end 
         
         
         
        else 
            outputChatBox("Many players on team immigrants, the server will set you on the other team.", client) 
            x, y, z = getElementPosition(spawnPointPolice) 
            if setPlayerTeam" class="kw6">setPlayerTeam ( client, team_policeSP ) then 
                outputChatBox("You are on police team, catch them!", client) 
                for i, b in ipairs(getPlayersInTeam(team_policeSP)) do 
                    createBlipAttachedTo ( client, 0, 3, 0, 0, 255, 255, 0, 99999.0,  b) 
                end 
                 
                playersOnPolice = countPlayersInTeam ( team_policeSP ) 
                playersOnImmigrants = countPlayersInTeam ( team_immigrantsSP ) 
                outputChatBox("Number of immigrants: " .. playersOnImmigrants, client) 
                outputChatBox("Number of police: " .. playersOnPolice, client) 
            end 
        end 
    end 
  

No errors on console! but when the timer reach 0 , I keep with black screen.. no spawn for me..

Can anyone help me here?

Thanks alot again.

Link to comment

Stop pming people (me) if you need help.

First thing I noticed is that you didn't add the even serverside with addEvent("buttonClicked", true), this should've given an error in /debugscript 3.

But since there are no errors (atleast you say so), there are likely other problems.

Link to comment
Stop pming people (me) if you need help.

First thing I noticed is that you didn't add the even serverside with addEvent("buttonClicked", true), this should've given an error in /debugscript 3.

But since there are no errors (atleast you say so), there are likely other problems.

Thanks for ur reply

Its there before the function, I just didnt copy to the show u guys.

So I dont see where is the problem, I guess I am using tables like I should? and client info is being stored right?

Sorry about the PM .

Link to comment

Fixed!

If anyone will have the same problem, I did these :

on the client side , i changed the function triggerServerEvent to:

triggerServerEvent("buttonClicked",getLocalPlayer(), equipa)

and then on the joinHandler function, instead of client I changed to source.

and its working :D

Link to comment
Stop pming people (me) if you need help.

Yeah, I got a PM of him being really nice saying i always know whats right, and to answer his post...

Well I looked ur posts and u know some shiits, so I though u could help me.

But then I sadly realize you dont help much . So I gave up PMing u :S

But its okay bro, no problem for me, I am okay. There are many good people here helping me :)

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