Jump to content

setElementModel


Recommended Posts

function onGuiClick() 
if (source == GUIEditor.button[1]) then 
local rowa = guiGridListGetSelectedItem( GUIEditor.gridlist[1] ) 
local namea = guiGridListGetItemText( GUIEditor.gridlist[1], rowa, columna) 
local rowb = guiGridListGetSelectedItem( GUIEditor.gridlist[2] ) 
local nameb = guiGridListGetItemText( GUIEditor.gridlist[2], rowb, columnb) 
if namea == "Pershing Square" then 
triggerServerEvent("pershingsquarespawn", localPlayer) 
guiSetVisible(GUIEditor.window[1], false) 
showCursor(false) 
end 
if namea == "Idlewood Gas Station (IGS)" then 
triggerServerEvent("IGS", localPlayer) 
guiSetVisible(GUIEditor.window[1], false) 
showCursor(false) 
end 
if nameb == "Army (287)" then 
setElementModel(localPlayer, 287) 
end 
end 
end 
addEventHandler("onClientGUIClick", root, onGuiClick) 

It spawns me on the right place but it doesn't set my skin to 287......Any help?

Link to comment

What do you mean 'it spawns me on the right place' i don't see any spawn function in your code

However, try this:

  
       function onGuiClick() 
        if (source == GUIEditor.button[1]) then 
        local rowa = guiGridListGetSelectedItem( GUIEditor.gridlist[1] ) 
        local namea = guiGridListGetItemText( GUIEditor.gridlist[1], rowa, columna) 
        local rowb = guiGridListGetSelectedItem( GUIEditor.gridlist[2] ) 
        local nameb = guiGridListGetItemText( GUIEditor.gridlist[2], rowb, columnb) 
        if namea == "Pershing Square" then 
        triggerServerEvent("pershingsquarespawn", localPlayer) 
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
        elseif  namea == 'Idlewood Gas Station (IGS)' 
        triggerServerEvent("IGS", localPlayer) 
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
        elseif nameb == "Army (287)" then 
        setElementModel(287) 
end 
end 
end 
addEventHandler("onClientGUIClick", root, onGuiClick) 

Link to comment
What do you mean 'it spawns me on the right place' i don't see any spawn function in your code

However, try this:

  
       function onGuiClick() 
        if (source == GUIEditor.button[1]) then 
        local rowa = guiGridListGetSelectedItem( GUIEditor.gridlist[1] ) 
        local namea = guiGridListGetItemText( GUIEditor.gridlist[1], rowa, columna) 
        local rowb = guiGridListGetSelectedItem( GUIEditor.gridlist[2] ) 
        local nameb = guiGridListGetItemText( GUIEditor.gridlist[2], rowb, columnb) 
        if namea == "Pershing Square" then 
        triggerServerEvent("pershingsquarespawn", localPlayer) 
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
        elseif  namea == 'Idlewood Gas Station (IGS)' 
        triggerServerEvent("IGS", localPlayer) 
        guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
        elseif nameb == "Army (287)" then 
        setElementModel(287) 
end 
end 
end 
addEventHandler("onClientGUIClick", root, onGuiClick) 

I triggered those two events server side to spawn the player. +You missed an 'end' on line 46. Still doesn't work.

EDIT: Looks like WhoAmI posted, let me try what you have said as well.

Link to comment

@WhoAmI, here's my server side:

--Place Events 
addEvent("pershingsquarespawn", true) 
addEvent("IGS", true) 
  
function onLogin() 
player = source 
triggerClientEvent(player, "onClientPlayerLogin", player) 
end 
addEventHandler("onPlayerLogin", root, onLogin) 
  
addEventHandler("pershingsquarespawn", root, 
function() 
spawnPlayer(source, 1473.6114501953, -1714.1791992188, 14.046875) 
fadeCamera(source, true) 
setCameraTarget(source, source) 
end 
) 
  
addEventHandler("IGS", root, 
function() 
spawnPlayer(source, 1927.0316162109, -1764.384765625, 13.539072036743) 
fadeCamera(source, true) 
setCameraTarget(source, source) 
end 
) 

Link to comment

@Xeon

that's wrong you need to add the element here

e0e42da714.png

anyways

       function onGuiClick() 
        if (source == GUIEditor.button[1]) then 
            local rowa = guiGridListGetSelectedItem( GUIEditor.gridlist[1] ) 
            local namea = guiGridListGetItemText( GUIEditor.gridlist[1], rowa, columna) 
            local rowb = guiGridListGetSelectedItem( GUIEditor.gridlist[2] ) 
            local nameb = guiGridListGetItemText( GUIEditor.gridlist[2], rowb, columnb) 
            if (rowa and rowa ~= -1) then 
                if namea == "Pershing Square" then 
                triggerServerEvent("pershingsquarespawn", localPlayer) 
                elseif  namea == 'Idlewood Gas Station (IGS)' 
                triggerServerEvent("IGS", localPlayer) 
                end 
            elseif (rowb and rowb ~= -1) then 
                if nameb == "Army (287)" then 
                setElementModel(localPlayer,287) 
                end  
            end 
            guiSetVisible(GUIEditor.window[1], false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", root, onGuiClick) 

Link to comment

Your client side code will finish execute before the server code start's to execute, as you have a ping around 50 this means a ~50 ms delay which in reality means that you set the skin ID to 287 (only you will be able to se that as it's client side). Then, 50ms later the spawn function on the server is triggered:

bool spawnPlayer ( player thePlayer, float x, float y, float z, [ int rotation = 0, int skinID = 0, int interior = 0, int dimension = 0, team theTeam = nil ] ) 

As you can see here, skinID is an optional argument in the spawn function which you haven't provided, that means it will set your skin to 0 (also known as CJ).

So basically your code works, it does change your skin, but it also turns it back to CJ a few milliseconds later. I recommend you to set the skin either after calling the spawnPlayer, or supply that as an argument.

Link to comment
Your client side code will finish execute before the server code start's to execute, as you have a ping around 50 this means a ~50 ms delay which in reality means that you set the skin ID to 287 (only you will be able to se that as it's client side). Then, 50ms later the spawn function on the server is triggered:
bool spawnPlayer ( player thePlayer, float x, float y, float z, [ int rotation = 0, int skinID = 0, int interior = 0, int dimension = 0, team theTeam = nil ] ) 

As you can see here, skinID is an optional argument in the spawn function which you haven't provided, that means it will set your skin to 0 (also known as CJ).

So basically your code works, it does change your skin, but it also turns it back to CJ a few milliseconds later. I recommend you to set the skin either after calling the spawnPlayer, or supply that as an argument.

Thanks!

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