Bonjour,
Je me permet de posté ici ma demande de soutien , j'ai trouvé il y a de ca un petit moment un script de Bonb Shop seul probléme il et bugé et je n'arrive a rien je débute en LUA , tous ce que je demande c'est de m'expliqué l'erreur que je puisse apprendre et par la méme occasion les réssoudre par la futur
Voici donc le code :
cost = 10000 --This is our global cost value, for how much a bomb costs
bombshopCol = createColSphere ( 1945.15491, -1759.58777, 12.59090, 2.4 ) --we also make a col object to detect people entering it in the main body of the code so it can be used in event handlers.
-- addEventHandler ( "onResourceStart", getRootElement(), bombshopLoad ) --when the resource is started
function bombshopLoad ( name )
if name ~= getThisResource () then return else --add a check to make sure that its the current resource
local marker = createMarker ( 1945.15491, -1759.58777, 12.59090, "cylinder", 3, 255, 0, 0, 200 ) --create a pretty marker for our bombshop
bombshopMenu = textCreateDisplay () --create a menu text display
--Create our text items. Displays instructions, the cost, and all possible bomb times.
local menuText1 = textCreateTextItem ( "Press 1-5 to choose your bomb.", 0.15, 0.2, 2, 255, 255, 255, 255, 1.2 )
local menuText2 = textCreateTextItem ( "Cost: $"..cost, 0.15, 0.227, 2, 255, 255, 255, 255, 1.2 ) --note the cost variable is used to display the cost
local menuText3 = textCreateTextItem ( "1) Time bomb", 0.15, 0.262, 2, 255, 255, 255, 255, 1.2 )
local menuText4 = textCreateTextItem ( "2) Detonator bomb", 0.15, 0.289, 2, 255, 255, 255, 255, 1.2 )
local menuText5 = textCreateTextItem ( "3) Engine start bomb", 0.15, 0.316, 2, 255, 255, 255, 255, 1.2 )
local menuText6 = textCreateTextItem ( "4) Weight bomb", 0.15, 0.37, 2, 255, 255, 255, 255, 1.2 )
--add all this text to our bombshopMenu display
textDisplayAddText ( bombshopMenu, menuText1 )
textDisplayAddText ( bombshopMenu, menuText2 )
textDisplayAddText ( bombshopMenu, menuText3 )
textDisplayAddText ( bombshopMenu, menuText4 )
textDisplayAddText ( bombshopMenu, menuText5 )
textDisplayAddText ( bombshopMenu, menuText6 )
end
end
addEventHandler ( "onColShapeHit", bombshopCol, bombshopEnter ) --when someone hits the bombshopCol collision shape
function bombshopEnter ( element, dim )
if ( getElementType ( element ) == "vehicle" ) then --check if the element is a vehicle
local player = getVehicleOccupant ( element, 0 ) --if it is, get the player inside this vehicle
if getElementData ( element, "bombType" ) == "0" then --if the bombtype is blank
textDisplayAddObserver ( bombshopMenu, player )
--bind all the keys according to the menu. we dont provide any special arguments as we can differentiate using keys
bindKey ( player, "1", "down", "fitBomb", element )
bindKey ( player, "2", "down", "fitBomb", element )
bindKey ( player, "3", "down", "fitBomb", element )
bindKey ( player, "4", "down", "fitBomb", element )
else
outputChatBox ( "This car is already rigged!", player ) --if the bombtype is not blank, display a message that a bomb is already fitted.
end
end
end
function fitBomb ( player, key, keyState, vehicle ) --this is the custom fitBomb function
if getPlayerMoney ( player ) >= cost then --first we check the player has enough money.
setElementData ( vehicle, "bombType", key ) --flag the vehicle with the bombtype that is desired - according to the key pressed
if key ~= "2" then --if the key does NOT == 2, in other words is not the detonator bomb
--then it must be a bomb that is activated like normal. Tell them to press fire to arm the bomb, and bind the fire key to the "armBomb" function
outputChatBox ( "Press fire to arm the bomb", player )
bindKey ( player, "vehicle_fire", "down", "armBomb", vehicle )
else --however, if it is the detonator bomb
outputChatBox ( "Use the detonator to trigger the bomb", player ) --tell them to use the detonator
giveWeapon ( player, 40 ) --give them a detonator
setElementData ( player, "detonaterVehicle", vehicle ) --flag the player with the vehicle which the detonator blows up
end
--get rid of all our keybinds, and remove the text for the bombshop
unbindKey ( player, "1", "down", "fitBomb" )
unbindKey ( player, "2", "down", "fitBomb" )
unbindKey ( player, "3", "down", "fitBomb" )
unbindKey ( player, "4", "down", "fitBomb" )
textDisplayRemoveObserver ( bombshopMenu, player )
--play an activation sound
playSoundFrontEnd ( player, 46 )
--and remove money according to the cost
takePlayerMoney ( player, math.abs(cost) )
else --if he doesnt have enough money, tell him he cant afford to fit one
outputChatBox ( "You cannot afford to fit a bomb!", player )
end
end
addEventHandler ( "onColShapeLeave", bombshopCol, bombshopLeave)--when someone leaves the bombshopCol
function bombshopLeave ( element, dim )
if getElementType ( element ) == "player" then --if the element is a player
--unbind all the keys to buy a bomb, and remove the menu.
unbindKey ( element, "1", "down", "fitBomb" )
unbindKey ( element, "2", "down", "fitBomb" )
unbindKey ( element, "3", "down", "fitBomb" )
unbindKey ( element, "4", "down", "fitBomb" )
textDisplayRemoveObserver ( bombshopMenu, element )
end
end
addEventHandler ( "onVehicleEnter", getRootElement(), bombshopVehicleEnter ) --when a vehicle is entered
function bombshopVehicleEnter ( player, seat, jacked )
local type = getElementData ( source, "bombType" ) --get the bomb type
if type == false then --if type returns false
setElementData ( source, "bombType", "0" ) --set it to a blank type
elseif type ~= "2" and getElementData ( source, "armed" ) == false then
bindKey ( player, "vehicle_fire", "down", "armBomb", source ) --if its not type 2, and the vehicle is nor armed bind the vehicle fire button to armBomb
elseif type ~= "2" and getElementData ( source, "armed" ) ~= false then --if it isnt type 2, but IS armed, then we initiate any bomb functions that might occur
unbindKey ( player, "vehicle_fire", "down", "armBomb" ) --start off by getting rid of the keybind
--ENGINE START BOMB.
if type == "3" and getElementData ( source, "armed" ) ~= false then --if the type is a engine start bomb, i.e. 3, then we need to blow the vehicle when a driver enters a vehicle.
if seat == 0 then --check if the seat the player got into was id 0 - i.e. driver seat
blowVehicle ( source ) --if it was, toast him
end
end
--WEIGHT BOMB
if type == "4" then --if it is a weight bomb, i.e. type 4, we need to blow the vehicle accoring to weight
local i = 0 --define a loop variable
local totalPassengers = 0 --define a loop total passengers
while i ~= 8 do --loop until i == 8
if ( getVehicleOccupant ( source, i ) ) then --check if the "i" id has a passenger inside
totalPassengers = totalPassengers + 1 --if it does, add totalPassengers by one
end
i = i + 1 --add the loop variable by one
end
if totalPassengers > 1 then --if the total passengers in the vehicle, is indeed greater than one
blowVehicle ( source ) --fry the vehicle.
end
end
end
end
addEventHandler ( "onVehicleExit", getRootElement(), bombshopVehicleExit ) --when a vehicle is exited
function bombshopVehicleExit ( player, seat, jacker )
unbindKey ( player, "vehicle_fire", "down", "armBomb" ) --get rid of any binds to activate the bomb.
end
--the arm bomb function - to activate it before the bomb can detonate
function armBomb ( source, key, keyState, vehicle )
setElementData ( vehicle, "armed", true ) --flag the vehicle as armed
outputChatBox ( "The bomb has been activated.", source ) --announce it
playSoundFrontEnd ( source, 42 ) --play an activation sound
unbindKey ( source, "vehicle_fire", "down", "armBomb" )--unbind the ability to activate it
if getElementData ( vehicle, "bombType" ) == "1" then --if the bomb is a timebomb
outputChatBox ( "10", source ) --start a chatbox countdown from 10
setTimer ( "timeBombCountDown", 1000, 1, 9, source, vehicle ) --set a timer to call the timbBombCountDown after 1 second, with arguements of 9 seconds remainging, the player and the vehicle
end
end
function timeBombCountDown ( currentTime, source, vehicle )
if currentTime ~= 0 then --if the time is not 0
playSoundFrontEnd ( source, 5 ) --play a timer sound
outputChatBox ( currentTime, source ) --announce the remaining time
currentTime = currentTime - 1 --change to a new time
setTimer ( "timeBombCountDown", 1000, 1, currentTime, source, vehicle ) --call the function again in one second with the new time
else --otherwise, if the time remaining is 0
outputChatBox ( "BOOOOOM!" ) --announce that it has been exploded
blowVehicle ( vehicle ) --blow it sky high.
end
end
------------------BOMB TWO - DETONATED ---------------
--Possibly the most complex bomb. Requires a player to detonate it on foot
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), bombshopWeaponSwitch ) --use the onPlayerWeaponSwitch function to detect when a player switches his weapon
function bombshopWeaponSwitch ( previousWeaponID, currentWeaponID )
if currentWeaponID == 40 then --if he switches it to ID 40, i.e. the detonator
bindKey ( source, "fire", "down", "detonateVehicle" ) --then bind his fire key to the detonateVehicle function
else
unbindKey ( source, "fire", "down", "detonateVehicle" ) --if it aint id 40, unbind it
end
end
function detonateVehicle ( source, key, keyState ) --the detonateVehicle function the bind is bound do
blowVehicle ( getElementData ( source, "detonaterVehicle" ) ) --find the vehicle that the detonator is attached to by looking up a flag on the player - then blow the crap out of it
end
addCommandHandler ( "money", "money" )
-------TEMP REMOVE FOR FINAL----
voici maintenant les erreurs :
[2014-04-25 13:27:50] WARNING: test\bomb_s.lua:4: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil]
[2014-04-25 13:27:50] WARNING: test\bomb_s.lua:26: Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil]
[2014-04-25 13:27:50] WARNING: test\bomb_s.lua:70: Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil]
[2014-04-25 13:27:50] WARNING: test\bomb_s.lua:82: Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil]
[2014-04-25 13:27:50] WARNING: test\bomb_s.lua:114: Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil]
[2014-04-25 13:27:50] WARNING: test\bomb_s.lua:145: Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil]
[2014-04-25 13:27:50] WARNING: test\bomb_s.lua:157: Bad argument @ 'addCommandHandler' [Expected function at argument 2, got string 'money']