Jump to content

How when the player join pick for him a specific persons ?


Recommended Posts

I want to spawn player with random specific persons

Just like

Varsity jacket <~~ person

Skater kid <~~ person

Bball player <~~ person

And let the console pick a one of them etc..

And spawn the player on this area

1957 , -2181 , 14

------------------------------------------------------------------------------------------

Look at my own

------------------------------------------------------------------------------------------

    local spawnpoint 
      
    addEventHandler("onResourceStart", resourceRoot, 
        function() 
            spawnpoint = getRandomSpawnPoint() 
            resetMapInfo() 
            for i,player in ipairs(getElementsByType("player")) do 
                spawn(player) 
            end 
        end 
    ) 
      
    function joinHandler ( ) 
        spawnPlayer (source, 1957, -2181, 14, 180, 99, 22) 
        fadeCamera (source, true) 
        setCameraTarget ( source, source ) 
    end 
    addEventHandler ( "onPlayerJoin" , getRootElement ( ) , joinHandler ) 
      
    function greetPlayer ( ) 
        outputChatBox ( "Thanks for join" , source, 0, 159, 255 ) 
    end 
    addEventHandler ( "onPlayerLogin", getRootElement(), greetPlayer ) 
      
    function onPlayerQuit() 
        local playerAccount = getPlayerAccount(source) 
        if (playerAccount) and not isGuestAccount(playerAccount) then 
            local playerMoney = getPlayerMoney(source) 
            local playerSkin = getElementModel(source) 
            setAccountData(playerAccount, "money", playerMoney) 
            setAccountData(playerAccount, "skin", playerSkin) 
        end 
    end 
    addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
      
    function onPlayerLogin() 
        local playerAccount = getPlayerAccount(source) 
        if (playerAccount) and not isGuestAccount(playerAccount) then 
            local playerMoney = tonumber(getAccountData(playerAccount, "money")) 
            local playerSkin = tonumber(getAccountData(playerAccount, "skin")) 
            if (playerMoney and playerSkin) then 
                setPlayerMoney(source, playerMoney) 
                setElementModel(source, playerSkin) 
            end 
        end 
    end 
    addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 
      
    function spawn(player) 
        if not isElement(player) then return end 
        if get("spawnreset") == "onSpawn" then 
            spawnpoint = getRandomSpawnPoint() 
        end 
        exports.spawnmanager:spawnPlayerAtSpawnpoint(player,spawnpoint,false) 
        setElementModel(player, tonumber(getElementData(player,"tempSkin"))) 
        fadeCamera(player, true) 
        setCameraTarget(player, player) 
        showChat(player, true) 
    end 
      
    function getRandomSpawnPoint () 
        local spawnpoints = getElementsByType("spawnpoint") 
        return spawnpoints[math.random(1,#spawnpoints)] 
    end 
      
    addEventHandler("onPlayerJoin", root, 
        function() 
            spawn(source) 
        end 
    ) 
      
    addEventHandler("onPlayerQuit",root, 
        function () 
            if getPlayerCount() == 1 and get("spawnreset") == "onServerEmpty" then 
                spawnpoint = getRandomSpawnPoint() 
            end 
        end 
    ) 
      
    addEventHandler("onPlayerWasted", root, 
        function() 
            setElementData(source,"tempSkin",getElementModel(source)) 
            setTimer(spawn, 1800, 1, source) 
        end 
    ) 
  

But it don't work -_-

Link to comment

You can create a table with available persons:

aPersons = { 111, 116, 10, 94 } --Change to ID Skins that you want 

And later, access the item using rand.math()

setElementModel(getLocalPlayer(), math.random[#aPersons]) 

    function joinHandler ( ) 
        spawnPlayer (source, 1957, -2181, 14, 180, 99, 22) 
        fadeCamera (source, true) 
        setCameraTarget ( source, source ) 
    end 
  
    function greetPlayer ( ) 
        aPersons = { 111, 116, 10, 94 } 
        outputChatBox ( "Thanks for join" , source, 0, 159, 255 ) 
        setElementModel(source, math.random[#aPersons]) 
    end 
    addEventHandler ( "onPlayerLogin", getRootElement(), greetPlayer ) 
  
-- Don't forget to put the rest of your original code 

I think it works.

Link to comment
Guest Guest4401

@StanleySathler

It should be

aPersons[math.random(#aPersons)] 

and not

math.random[#aPersons] 

#aPersons -- This will return the number 4, because the table has 4 values 
math.random(#aPersons) -- This will pick a random number from 1 to 4 
  
--Assuming that randomly it picked 3, 
aPersons[math.random(#aPersons)] 
aPersons[3] -- which will be the skin ID : 10 

Link to comment
#aPersons -- This will return the number 4, because the table has 4 values

math.random(#aPersons) -- This will pick a random number from 1 to 4

--Assuming that randomly it picked 3,

aPersons[math.random(#aPersons)]

aPersons[3] -- which will be the skin ID : 10

Where could i put this here ?

local spawnpoint 
      
    addEventHandler("onResourceStart", resourceRoot, 
        function() 
            spawnpoint = getRandomSpawnPoint() 
            resetMapInfo() 
            for i,player in ipairs(getElementsByType("player")) do 
                spawn(player) 
            end 
        end 
    ) 
      
     function joinHandler ( ) 
        spawnPlayer (source, 1957, -2181, 14, 0, 0, 0) 
        fadeCamera (source, true) 
        setCameraTarget ( source, source ) 
    end 
  
    function greetPlayer ( ) 
        aPersons = { 111, 116, 10, 94 } 
        outputChatBox ( "Thanks for join" , source, 0, 159, 255 ) 
        setElementModel(source,  aPersons[math.random(#aPersons)]) 
    end 
    addEventHandler ( "onPlayerLogin", getRootElement(), greetPlayer )Player ) 
      
    function onPlayerQuit() 
        local playerAccount = getPlayerAccount(source) 
        if (playerAccount) and not isGuestAccount(playerAccount) then 
            local playerMoney = getPlayerMoney(source) 
            local playerSkin = getElementModel(source) 
            setAccountData(playerAccount, "money", playerMoney) 
            setAccountData(playerAccount, "skin", playerSkin) 
        end 
    end 
    addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
      
    function onPlayerLogin() 
        local playerAccount = getPlayerAccount(source) 
        if (playerAccount) and not isGuestAccount(playerAccount) then 
            local playerMoney = tonumber(getAccountData(playerAccount, "money")) 
            local playerSkin = tonumber(getAccountData(playerAccount, "skin")) 
            if (playerMoney and playerSkin) then 
                setPlayerMoney(source, playerMoney) 
                setElementModel(source, playerSkin) 
            end 
        end 
    end 
    addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 
      
    function spawn(player) 
        if not isElement(player) then return end 
        if get("spawnreset") == "onSpawn" then 
            spawnpoint = getRandomSpawnPoint() 
        end 
        exports.spawnmanager:spawnPlayerAtSpawnpoint(player,spawnpoint,false) 
        setElementModel(player, tonumber(getElementData(player,"tempSkin"))) 
        fadeCamera(player, true) 
        setCameraTarget(player, player) 
        showChat(player, true) 
    end 
      
    function getRandomSpawnPoint () 
        local spawnpoints = getElementsByType("spawnpoint") 
        return spawnpoints[math.random(1,#spawnpoints)] 
    end 
      
    addEventHandler("onPlayerJoin", root, 
        function() 
            spawn(source) 
        end 
    ) 
      
    addEventHandler("onPlayerQuit",root, 
        function () 
            if getPlayerCount() == 1 and get("spawnreset") == "onServerEmpty" then 
                spawnpoint = getRandomSpawnPoint() 
            end 
        end 
    ) 
      
    addEventHandler("onPlayerWasted", root, 
        function() 
            setElementData(source,"tempSkin",getElementModel(source)) 
            setTimer(spawn, 1800, 1, source) 
        end 
    ) 
  

And here

--Assuming that randomly it picked 3,

aPersons[math.random(#aPersons)]

aPersons[3] -- which will be the skin ID : 10

Who is these 3 persons ? are they specific ?

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