Jump to content

Spawn Player


AlvareZ_

Recommended Posts

Hi guys, I have this Script, But when i press "Jugar", Dont Spawn, please help me!

Client:

local x, y = guiGetScreenSize() 
  
  
SkinAnims = {"Invite_Yes","prtial_gngtllkG","Invite_No"} 
NewSkin = false 
StartSkin = 254 
  
  
  
function SelectSkin () 
    setCameraMatrix( -1278.16663, 46.63542, 32.40625, -1278.73425, 44.20432, 32.40625) 
    skin = createPed ( StartSkin, -1278.73425, 44.20432, 32.40625,-10 ) 
setElementInterior ( getLocalPlayer(), 0) 
setPedFrozen(skin, true) 
stopSound(Music) 
    setPedAnimation( skin, "GANGS", SkinAnims[math.random(1,3)]) 
    fadeCamera( true, 10) 
    setTime(0,0) 
 removeEventHandler("onClientPreRender", root, interpolateCam1) 
 removeEventHandler("onClientPreRender", root, interpolateCam) 
    SkinSelectMusic = playSound("main2.mp3") 
    showCursor(true) 
    showChat(false) 
       guiSetVisible(lnextskin, true) 
       guiSetVisible(rnextskin, true) 
       guiSetVisible(spawnskin, true) 
    showPlayerHudComponent ( "radar", false ) 
end 
addEvent("allLogear", true) 
addEventHandler("allLogear", getLocalPlayer(), SelectSkin) 
  
function onClickSkin() 
  if (source == rnextskin) then 
    if getElementModel(skin)  == 254 and (source == rnextskin) then 
      setElementModel(skin, 287) 
    elseif getElementModel(skin) == 287 and (source == rnextskin) then 
      setElementModel(skin, 247) 
    elseif getElementModel(skin) == 247 and (source == rnextskin) then 
      setElementModel(skin, 248) 
    elseif getElementModel(skin) == 248 and (source == rnextskin) then 
      setElementModel(skin, 262) 
    elseif getElementModel(skin) == 262 and (source == rnextskin) then 
      setElementModel(skin, 253) 
    elseif getElementModel(skin) == 253 and (source == rnextskin) then 
      setElementModel(skin, 260) 
    elseif getElementModel(skin) == 260 and (source == rnextskin) then 
      setElementModel(skin, 249) 
    elseif getElementModel(skin) == 249 and (source == rnextskin) then 
      setElementModel(skin, 277) 
    elseif getElementModel(skin) == 277 and (source == rnextskin) then 
      setElementModel(skin, 274) 
    elseif getElementModel(skin) == 274 and (source == rnextskin) then 
      setElementModel(skin, 288) 
    elseif getElementModel(skin) == 288 and (source == rnextskin) then 
      setElementModel(skin, 259) 
    elseif getElementModel(skin) == 259 and (source == rnextskin) then 
      setElementModel(skin, 283) 
    elseif getElementModel(skin) == 283 and (source == rnextskin) then 
      setElementModel(skin, 254) 
end 
end 
end 
addEventHandler("onClientGUIClick", root, onClickSkin) 
  
function onClickSkin2() 
  if (source == lnextskin) then 
    if getElementModel(skin) == 283 then 
      setElementModel(skin, 259) 
    elseif getElementModel(skin) == 259 and (source == lnextskin) then 
      setElementModel(skin, 288) 
    elseif getElementModel(skin) == 288 and (source == lnextskin) then 
      setElementModel(skin, 2274) 
    elseif getElementModel(skin) == 274 and (source == lnextskin) then 
      setElementModel(skin, 277) 
    elseif getElementModel(skin) == 277 and (source == lnextskin) then 
      setElementModel(skin, 249) 
    elseif getElementModel(skin) == 249 and (source == lnextskin) then 
      setElementModel(skin, 260) 
    elseif getElementModel(skin) == 260 and (source == lnextskin) then 
      setElementModel(skin, 253) 
    elseif getElementModel(skin) == 253 and (source == lnextskin) then 
      setElementModel(skin, 262) 
    elseif getElementModel(skin) == 262 and (source == lnextskin) then 
      setElementModel(skin, 248) 
    elseif getElementModel(skin) == 248 and (source == lnextskin) then 
      setElementModel(skin, 247) 
    elseif getElementModel(skin) == 247 and (source == lnextskin) then 
      setElementModel(skin, 287) 
    elseif getElementModel(skin) == 287 and (source == lnextskin) then 
      setElementModel(skin, 254) 
    elseif getElementModel(skin) == 254 and (source == lnextskin) then 
      setElementModel(skin, 283) 
end 
end 
end 
addEventHandler("onClientGUIClick", root, onClickSkin2) 
  
  
  
function SpawnPlayer() 
if (source == spawnskin) then 
    local r,g,b = math.random(0,255),math.random(0,255),math.random(0,255) 
    triggerServerEvent ( "onClientWantsToSpawn", getLocalPlayer(), getLocalPlayer(),StartSkin,r,g,b ) 
    unbindKey("arrow_r","down",NextSkin) 
    unbindKey("arrow_l","down",LastSkin) 
    unbindKey("lshift","down",SpawnPlayer) 
    setTime(12,0) 
    stopSound(SkinSelectMusic) 
    removeEventHandler("onClientRender",getRootElement(),AnnounceSkinJob) 
    showCursor(false) 
    showChat(true) 
    showPlayerHudComponent ( "radar", true ) 
    guiSetVisible(lnextskin,false) 
    guiSetVisible(rnextskin,false) 
    guiSetVisible(spawnskin,false) 
    setElementData(getLocalPlayer(),"red",r) 
    setElementData(getLocalPlayer(),"green",g) 
    setElementData(getLocalPlayer(),"blue",b) 
end 
end 
  
  
  
  
lnextskin = guiCreateButton(0.30, 0.46, 0.09, 0.10, "<<",true) 
guiSetProperty(lnextskin,"PushedTextColour","FFFFFF00") 
guiSetFont(lnextskin,"sa-header") 
guiSetVisible(lnextskin, false) 
rnextskin = guiCreateButton(0.62, 0.46, 0.09, 0.10, ">>",true) 
guiSetProperty(rnextskin,"PushedTextColour","FFFFFF00") 
guiSetFont(rnextskin,"sa-header") 
guiSetVisible(rnextskin, false) 
spawnskin = guiCreateButton(0.42, 0.88, 0.16, 0.09, "Jugar",true) 
guiSetProperty(spawnskin,"PushedTextColour","FFFFFF00") 
guiSetFont(spawnskin,"sa-header") 
guiSetVisible(spawnskin, false) 
  

Server:

addEventHandler("onPlayerLogin", root, 
function() 
triggerClientEvent("allLogear", source) 
end) 
  
function SpawnPlayer(thePlayer,skin,r,g,b) 
    spawnPlayer ( thePlayer, 1539.7673339844,-1352.8256835938,329.46545410156, 90.0, skin ) 
    setCameraTarget (source, source) 
    createBlipAttachedTo(source,0,2,r,g,b) 
    setPlayerMoney(thePlayer,StartMoney) 
    playerSkin[thePlayer] = {skin,r,g,b} 
    setElementData(thePlayer,"Score",0) 
    setPlayerNametagShowing ( thePlayer, false) 
end 
addEvent( "onClientWantsToSpawn", true ) 
addEventHandler( "onClientWantsToSpawn", getRootElement(), SpawnPlayer ) 
  
addEventHandler ( "onPlayerQuit", getRootElement(), 
function() 
    local attachedElements = getAttachedElements ( source ) 
        if ( attachedElements ) then 
            for k,v in ipairs ( attachedElements ) do 
                if ( getElementType ( v ) == "blip" ) then 
                    destroyElement(v) 
                else 
            end 
        end 
    end 
end) 
  
function PlayerDied(ammo,killer) 
    if killer and getElementType ( killer ) == "player" then 
        setPlayerMoney(killer,getPlayerMoney(killer)+CashForKill) 
        local Score = getElementData(killer,"Score") 
        setElementData(killer,"Score",Score+1) 
    end 
setTimer(PlayerRespawn,1000,1,source) 
end 
addEventHandler("onPlayerWasted",getRootElement(),PlayerDied) 
  
  
function FixPlayerVehicle(hitElement,number) 
    local money = getPlayerMoney(hitElement) 
        if money < PayNSprayCost then 
            outputChatBox("*PM: You don't have enought cash.",hitElement,170,0,0,true) 
        else 
            if getPedOccupiedVehicle(hitElement) then 
            local vehicle = getPedOccupiedVehicle(hitElement) 
            fixVehicle(vehicle) 
            playSoundFrontEnd(hitElement,16) 
            toggleAllControls(hitElement,false) 
            setPlayerMoney(hitElement,money-PayNSprayCost) 
        local vehicle = getPedOccupiedVehicle(hitElement) 
            setElementFrozen(vehicle,true) 
            setTimer(function() 
            toggleAllControls(hitElement,true) 
            setCameraTarget (hitElement, hitElement) 
            setElementFrozen(vehicle,false) 
            end,2500,1) 
                if number == 1 then 
                    setCameraMatrix(hitElement,1032.7685546875,-1039.337890625,45.220012664795,1030.095703125,-1027.6357421875,40.220008850098) 
                elseif number == 2 then 
                    setCameraMatrix(hitElement,489.150390625,-1728.8310546875,31.169326782227,488.6884765625,-1734.04296875,21.179261207581) 
                elseif number == 3 then 
                    setCameraMatrix(hitElement,2076.5859375,-1831.4208984375,18.546875,2072.626953125,-1831.361328125,18.546875) 
                else 
            end 
        end 
    end 
 end 
  
addEvent( "onBoughtWeapon", true ) 
addEventHandler( "onBoughtWeapon", getRootElement(), 
function(thePlayer,id,cash) 
    setPlayerMoney(thePlayer,getPlayerMoney(thePlayer)-cash) 
        if id == 500 then 
            setPedArmor ( thePlayer, 100 ) 
        else 
        giveWeapon ( thePlayer, id, 120 ) 
    end 
end) 
  
addEvent( "onBoughtBurger", true ) 
addEventHandler( "onBoughtBurger", getRootElement(), 
function(thePlayer,cash) 
    setPlayerMoney(thePlayer,getPlayerMoney(thePlayer)-cash) 
    setElementHealth(thePlayer,getElementHealth(thePlayer)+cash) 
        if getElementHealth > 100 then 
        setElementHealth(thePlayer,100) 
    end 
end) 
  

Link to comment

Same here, didn't read full code but it's wrong on the first sight.

Why do you set the visibility of a single button?

guiSetVisible(spawnskin, true) 
spawnskin is the button, or isn't this button attached to a window (gui) 
 

+ Apart from that you don't have an event for the click

addEventHandler("onClientGUIClick", spawnskin, functionName) 

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