Jump to content

Spawn Gui does not work


Einheit-101

Recommended Posts

Hello Comrades! I have a little problem! I wanted to make a script that opens a window which lets you choose 2 different spawn points: 1 angel Pine, the other Blueberry acres! But it outputs some error messages:

Unexpected error: Spawn GUI has not been created. (My debug outputChatbox)

broph.lua:33: Bad argument @ addEventHandler

broph.lua:51: Bad argument @ addEventHandler

broph.lua:60: Bad argument @ ShowCursor

broph.lua:61: Bad argument @ attempt to call global setInputEnabled (a nil value)

  
function createSpawnWindow() 
    local X = 0.375 
    local Y = 0.375 
    local Width = 0.25 
    local Height = 0.25 
    wdwSpawn = guiCreateWindow(X, Y, Width, Height, "Select a Spawn area", true) 
  
    X = 0.415 
    Y = 0.7 
    Width = 0.25 
    Height = 0.2 
    btnPine = guiCreateButton(X, Y, 0.3, 0.15, "Angel Pine", true, wdwSpawn) 
    btnBerry = guiCreateButton(X, Y, 0.5, 0.15, "Blueberry", true, wdwSpawn) 
    guiSetVisible(wdwSpawn, false) 
end 
addEventHandler ( "onClientResourceStart", getRootElement(), createSpawnWindow ) 
  
function angelpine(button, state) 
    if button == "left" and state == "up" then 
        spawnPlayer(client, -2138.8+math.random(1,5), -2352+math.random(4,7), 37.732, 90, math.random(281,286)) 
        fadeCamera(client, true) 
        setCameraTarget(player, client) 
        giveWeapon(player, 25, 25) 
        givePlayerMoney(player, 250) 
        outputChatBox("Spawning in Angel Pine...") 
  
        guiSetInputEnabled(false) 
        guiSetVisible(wdwSpawn, false)--208.2, -240, 1.8 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", btnPine, angelpine, false) 
  
  
function blueberry(button, state) 
    if button == "left" and state == "up" then 
        spawnPlayer(client, 208.2+math.random(1,3),-240+math.random(1,3), 1.8, 90, math.random(281,286)) 
        fadeCamera(client, true) 
        setCameraTarget(player, client) 
        giveWeapon(player, 25, 25) 
        givePlayerMoney(player, 250) 
        outputChatBox("Spawning in Blueberry...") 
  
        guiSetInputEnabled(false) 
        guiSetVisible(wdwSpawn, false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", btnPine, blueberry, false) 
  
  
function window(ammo, attacker, weapon, bodypart) 
        if (wdwSpawn ~= nil) then 
            guiSetVisible(wdwSpawn, true) 
        else 
            outputChatBox("Unexpected error: Spawn GUI has not been created.") 
            end  
            showCursor(true) 
            guiSetInputEnabled(true) 
end 
  
  
function start() 
setTimer(window, 9000, 1) 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), start) 
  
function start() 
setTimer(window, 9000, 1) 
end 
addEventHandler ( "onClientResourceStart", getRootElement(), start ) 
  
function start() 
setTimer(window, 9000, 1) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), start ) 
  

Link to comment

Well, you are messing client functions/events with server functions/events, use this one instead,

client side:

local X = 0.375 
local Y = 0.375 
local Width = 0.25 
local Height = 0.25 
wdwSpawn = guiCreateWindow(X, Y, Width, Height, "Select a Spawn area", true) 
X = 0.415 
Y = 0.7 
Width = 0.25 
Height = 0.2 
btnPine = guiCreateButton(X, Y, 0.3, 0.15, "Angel Pine", true, wdwSpawn) 
btnBerry = guiCreateButton(X, Y, 0.5, 0.15, "Blueberry", true, wdwSpawn) 
guiSetVisible(wdwSpawn, false) 
  
function angelpine(button, state) 
    if button == "left" and state == "up" then 
        triggerServerEvent("spawn",getLocalPlayer(),getLocalPlayer(),"angel") 
        guiSetInputEnabled(false) 
        guiSetVisible(wdwSpawn, false)--208.2, -240, 1.8 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", btnPine, angelpine, false) 
   
function blueberry(button, state) 
    if button == "left" and state == "up" then 
        triggerServerEvent("spawn",getLocalPlayer(),getLocalPlayer(),"blueberry") 
        guiSetInputEnabled(false) 
        guiSetVisible(wdwSpawn, false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", btnBerry, blueberry, false) 
  
function window(ammo, attacker, weapon, bodypart) 
if (wdwSpawn ~= nil) then 
    guiSetVisible(wdwSpawn, true) 
    else 
    outputChatBox("Unexpected error: Spawn GUI has not been created.") 
    end 
    showCursor(true) 
    guiSetInputEnabled(true) 
end 
   
function start() 
setTimer(window, 9000, 1) 
end 
addEventHandler ( "onClientPlayerWasted", getLocalPlayer(), start) 
  
function start2() 
setTimer(window, 1000, 1) 
end 
addEventHandler ( "onClientResourceStart", getRootElement(), start2) 

server side:

  
addEvent("spawn",true) 
addEventHandler("spawn",getRootElement(), 
function (client,where) 
if where == "blueberry" then 
spawnPlayer(client, 208.2+math.random(1,3),-240+math.random(1,3), 1.8, 90, math.random(281,286)) 
fadeCamera(client, true) 
setCameraTarget(client, client) 
giveWeapon(client, 25, 25) 
givePlayerMoney(client, 250) 
outputChatBox("Spawning in Blueberry...",client) 
elseif where == "angel" then 
spawnPlayer(client, -2138.8+math.random(1,5), -2352+math.random(4,7), 37.732, 90, math.random(281,286)) 
fadeCamera(client, true) 
setCameraTarget(client, client) 
giveWeapon(client, 25, 25) 
givePlayerMoney(client, 250) 
outputChatBox("Spawning in Angel Pine...") 
  end 
end) 

You must define client or server at meta.xml, example:

  
<script src="script.lua" type="client" />        

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