I cant seem to get this to work, i fixed everything so far except
ERROR:ARPGSpawnMenu\SpawnC.lua:215 attempt to index global 'classes' ( a nil value )
I checked and checked and that is something i cant seem to figure out! Thanks in advanced and heres my code
SpawnC
------------------------------------------------------------------------------------------------------------------------------------------------------------------
GUIEditor = {
button = {},
window = {},
}
addEventHandler("onPlayerWasted", resourceRoot,
function()
GUIEditor.window[1] = guiCreateWindow(56, 343, 262, 370, "", false)
guiWindowSetSizable(GUIEditor.window[1], false)
losSantos = guiCreateButton(10, 40, 243, 44, "Los Santos", false, GUIEditor.window[1])
LV = guiCreateButton(10, 94, 243, 44, "Las Venturas", false, GUIEditor.window[1])
SF = guiCreateButton(10, 148, 243, 44, "San Fierro", false, GUIEditor.window[1])
RC = guiCreateButton(10, 202, 243, 44, "Red County", false, GUIEditor.window[1])
BC = guiCreateButton(10, 256, 243, 44, "Bone County", false, GUIEditor.window[1])
addEventHandler ( "onClientGUIClick", losSantos, showLS, false )
addEventHandler ( "onClientGUIClick", lasVenturas, showLV, false )
addEventHandler ( "onClientGUIClick", sanFierro, showSF, false )
addEventHandler ( "onClientGUIClick", redCounty, showRC, false )
addEventHandler ( "onClientGUIClick", boneCounty, showBC, false )
end
)
addEventHandler("onPlayerLogin", resourceRoot,
function()
GUIEditor.window[1] = guiCreateWindow(56, 343, 262, 370, "", false)
guiWindowSetSizable(GUIEditor.window[1], false)
losSantos = guiCreateButton(10, 40, 243, 44, "Los Santos", false, GUIEditor.window[1])
lasVenturas = guiCreateButton(10, 94, 243, 44, "Las Venturas", false, GUIEditor.window[1])
sanFierro = guiCreateButton(10, 148, 243, 44, "San Fierro", false, GUIEditor.window[1])
redCounty = guiCreateButton(10, 202, 243, 44, "Red County", false, GUIEditor.window[1])
boneCounty = guiCreateButton(10, 256, 243, 44, "Bone County", false, GUIEditor.window[1])
addEventHandler ( "onClientGUIClick", losSantos, showLS, false )
addEventHandler ( "onClientGUIClick", lasVenturas, showLV, false )
addEventHandler ( "onClientGUIClick", sanFierro, showSF, false )
addEventHandler ( "onClientGUIClick", redCounty, showRC, false )
addEventHandler ( "onClientGUIClick", boneCounty, showBC, false )
end
)
function showLS()
menuState = "LS"
end
function showLV()
menuState = "LV"
end
function showSF()
menuState = "SF"
end
function showRC()
menuState = "RC"
end
function showBC()
menuState = "BC"
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------
if menuState == "LS" then
classes = {
[1]={name="Police", location="Los Santos", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[2]={name="Police", location="Los Santos", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[3]={name="Police", location="Los Santos", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[4]={name="Police", location="Los Santos", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[5]={name="Police", location="Los Santos", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[6]={name="Police", location="Los Santos", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[7]={name="Police", location="Los Santos", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[8]={name="Police", location="Los Santos", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false}
}
elseif menuState == "LV" then
classes = {
[1]={name="Police", location="Las Venturas", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[2]={name="Police", location="Las Venturas", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[3]={name="Police", location="Las Venturas", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[4]={name="Police", location="Las Venturas", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[5]={name="Police", location="Las Venturas", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[6]={name="Police", location="Las Venturas", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[7]={name="Police", location="Las Venturas", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[8]={name="Police", location="Las Venturas", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false}
}
elseif menuState == "SF" then
classes = {
[1]={name="Police", location="San Fierro", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[2]={name="Police", location="San Fierro", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[3]={name="Police", location="San Fierro", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[4]={name="Police", location="San Fierro", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[5]={name="Police", location="San Fierro", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[6]={name="Police", location="San Fierro", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[7]={name="Police", location="San Fierro", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[8]={name="Police", location="San Fierro", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false}
}
elseif menuState == "BC" then
classes = {
[1]={name="Police", location="Bone County", skin=281, r=255, g=255, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[2]={name="Police", location="Bone County", skin=281, r=255, g=255, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[3]={name="Police", location="Bone County", skin=281, r=255, g=255, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[4]={name="Police", location="Bone County", skin=281, r=255, g=255, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[5]={name="Police", location="Bone County", skin=281, r=255, g=255, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[6]={name="Police", location="Bone County", skin=281, r=255, g=255, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[7]={name="Police", location="Bone County", skin=281, r=255, g=255, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[8]={name="Police", location="Bone County", skin=281, r=255, g=255, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false}
}
elseif menuState == "RC" then
classes = {
[1]={name="Police", location="Red County", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[2]={name="Police", location="Red County", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[3]={name="Police", location="Red County", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[4]={name="Police", location="Red County", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[5]={name="Police", location="Red County", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[6]={name="Police", location="Red County", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[7]={name="Police", location="Red County", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
[8]={name="Police", location="Red County", skin=281, r=0, g=0, b=255, camx=-2193.1892, camy=609.5613, camz=35.1641, x=-2185.3618, y=609.2630, z=35.1641, rotz=91, locked=false},
}
end
local weapons = {
["Police"]={3, 24, 23, 25 }
}
local curr = 1
addEvent("client:showSpawnMenu", true)
addEventHandler("client:showSpawnMenu", root,
function(class)
addEventHandler("onClientRender", root, drawSpawnInfo)
bindKey("arrow_l", "down", switchPrevious)
bindKey("arrow_r", "down", switchNext)
bindKey("space", "down", switchSpawn)
bindKey("enter", "down", spawn)
updateClassPos(curr)
end)
function switchSpawn()
end
function switchNext(_, state)
if state == "down" then
curr = curr + 1
if curr > #classes then curr = 1 end
outputChatBox(classes[curr].name)
updateClassPos(curr)
end
end
function switchPrevious(_, state)
if state == "down" then
curr = curr - 1
if curr < 1 then curr = #classes end
outputChatBox(classes[curr].name)
updateClassPos(curr)
end
end
function spawn()
if classes[curr].locked then
if isPlayerInTeam(localPlayer, classes[curr].team) then
normalSpawn()
else
outputChatBox("Only members of '"..classes[curr].team.."' are allowed to use this spawn!", 255, 0, 0)
end
else
normalSpawn()
end
end
function normalSpawn()
removeEventHandler("onClientRender", root, drawSpawnInfo)
unbindKey("arrow_l", "down", switchPrevious)
unbindKey("arrow_r", "down", switchNext)
unbindKey("enter", "down", spawn)
outputChatBox("Spawned")
if isElement(actor) then destroyElement(actor) end
triggerServerEvent("server:spawnOptions", localPlayer, classes[curr].skin, weapons[classes[curr].name][1], weapons[classes[curr].name][2], weapons[classes[curr].name][3], weapons[classes[curr].name][4], weapons[classes[curr].name][5], classes[curr].x, classes[curr].y, classes[curr].z, classes[curr].rotz)
end
function updateClassPos(num)
if not isElement(actor) then actor = createPed(classes[num].skin, classes[num].x, classes[num].y, classes[num].z) end
local cx, cy, cz = classes[num].camx, classes[num].camy, classes[num].camz
setPedRotation(actor, classes[num].rotz)
setElementPosition(actor, classes[num].x, classes[num].y, classes[num].z)
setElementModel(actor, classes[num].skin)
setCameraMatrix(cx, cy, cz, classes[num].x, classes[num].y, classes[num].z)
end
function isPlayerInTeam(src, TeamName)
if src and isElement ( src ) and getElementType ( src ) == "player" then
local team = getPlayerTeam(src)
if team then
if getTeamName(team) == TeamName then
return true
else
return false
end
end
end
end
function drawSpawnInfo()
local x, y, z = classes[curr].x, classes[curr].y, classes[curr].z
local sx, sy = getScreenFromWorldPosition(x, y, z)
if sx then
dxDrawFramedText(classes[curr].name, sx+65, sy-50, 10, 10, tocolor(classes[curr].r, classes[curr].g, classes[curr].b, 255), tocolor(0, 0, 0, 255), 2, "default-bold")
dxDrawFramedText(getZoneName(x, y, z, true).." (SPACE to change)", sx+65, sy, 10, 10, tocolor(255, 255, 255, 255), tocolor(0, 0, 0, 255), 1.5, "default-bold")
dxDrawFramedText("Weapons:", sx+65, sy+25, 10, 10, tocolor(255, 255, 255, 255), tocolor(0, 0, 0, 255), 1.5, "default-bold")
dxDrawFramedText("- "..getWeaponNameFromID(weapons[classes[curr].name][1]), sx+65, sy+50, 10, 10, tocolor(255, 255, 255, 255), tocolor(0, 0, 0, 255), 1.5, "default-bold")
dxDrawFramedText("- "..getWeaponNameFromID(weapons[classes[curr].name][2]), sx+65, sy+75, 10, 10, tocolor(255, 255, 255, 255), tocolor(0, 0, 0, 255), 1.5, "default-bold")
dxDrawFramedText("- "..getWeaponNameFromID(weapons[classes[curr].name][3]), sx+65, sy+100, 10, 10, tocolor(255, 255, 255, 255), tocolor(0, 0, 0, 255), 1.5, "default-bold")
dxDrawFramedText("- "..getWeaponNameFromID(weapons[classes[curr].name][4]), sx+65, sy+125, 10, 10, tocolor(255, 255, 255, 255), tocolor(0, 0, 0, 255), 1.5, "default-bold")
dxDrawFramedText("- "..getWeaponNameFromID(weapons[classes[curr].name][5]), sx+65, sy+150, 10, 10, tocolor(255, 255, 255, 255), tocolor(0, 0, 0, 255), 1.5, "default-bold")
end
end
function dxDrawFramedText ( message , left , top , width , height , color , frameColor , scale , font , alignX , alignY , clip , wordBreak , postGUI )
color = color or tocolor ( 255 , 255 , 255 , 255 )
frameColor = frameColor or tocolor ( 0 , 0 , 0 , 255 )
scale = scale or 1
font = font or "default"
alignX = alignX or "left"
alignY = alignY or "top"
clip = clip or false
wordBreak = wordBreak or false
postGUI = postGUI or false
local sMessage = message : gsub ( "#%x%x%x%x%x%x" , "" )
dxDrawText ( sMessage , left + 1 , top + 1 , width + 1 , height + 1 , frameColor , scale , font , alignX , alignY , clip , wordBreak , false )
dxDrawText ( sMessage , left + 1 , top - 1 , width + 1 , height - 1 , frameColor , scale , font , alignX , alignY , clip , wordBreak , false )
dxDrawText ( sMessage , left - 1 , top + 1 , width - 1 , height + 1 , frameColor , scale , font , alignX , alignY , clip , wordBreak , false )
dxDrawText ( sMessage , left - 1 , top - 1 , width - 1 , height - 1 , frameColor , scale , font , alignX , alignY , clip , wordBreak , false )
dxDrawText ( message , left , top , width , height , color , scale , font , alignX , alignY , clip , wordBreak , false )
end
SpawnS
addEventHandler("onPlayerLogin", root,
function()
triggerClientEvent ( "client:showSpawnMenu", getRootElement() )
end
)
addEventHandler ( "onPlayerWasted", root,
function()
triggerClientEvent ( "client:showSpawnMenu", getRootElement() )
end
)
addEventHandler ( "onPlayerWasted", root,
function( )
fadeCamera ( source, false, 1.0, 255, 0, 0 ) -- fade the player's camera to red over a period of 1 second
setTimer ( fadeCamera, 500, 1, source, true, 0.5 ) -- don't let it go to opaque red, interrupt it after half a second and fade back to normal
end
)
local ammo = {
[3]={1},
[24]={300},
[23]={300},
[25]={300}
}
addEvent("server:spawnOptions", true)
addEventHandler("server:spawnOptions", root,
function(skin, w1, w2, w3, w4, w5, x, y, z, rotz)
spawnPlayer(source, x, y, z, rotz, skin)
setElementInterior(source, 0)
setElementDimension(source, 0)
setCameraTarget(source, source)
giveWeapon(source, w1, ammo[w1][1])
giveWeapon(source, w2, ammo[w2][1])
giveWeapon(source, w3, ammo[w3][1], true)
giveWeapon(source, w4, ammo[w4][1])
giveWeapon(source, w5, ammo[w5][1])
end)
Meta
<meta>
<info author="Damien" name="Spawn" version="2.0" type="script"/>
<script src="SpawnS.lua" type="server"/>
<script src="SpawnC.lua" type="client"/>
</meta>