Jump to content

Simple problem


KariiiM

Recommended Posts

Posted

Helle guys, i have a small problem in same time big one, i scripter a simple shop for fun everything scripted sucessfully but ,When i add the Event "onVehicleExplosde",if just one player's vehicle explosed then all other vehicles gonna explodes too.

Thanks in advance.

function onVehicleExplode() 
      destroyElement(Vehicle) 
end 
addEventHandler("onVehicleExplode", getRootElement(), onVehicleExplode)  

Here's a part of my code:

--Ser-Side:

  
function onVehicleExplode() 
      destroyElement(Vehicle) 
end 
addEventHandler("onVehicleExplode", getRootElement(), onVehicleExplode) 
local Cash = 500000 
function rentVehicle  () 
if ( getPlayerMoney ( source ) <  Cash ) then 
outputChatBox("You need 300,000$ to rent this vehicle.", source, 255,0,0) 
else 
takePlayerMoney(source, Cash) 
  
if (getElementZoneName(source) == "Los Santos International") then 
Vehicle= createVehicle(425, 1924.5841064453, -2291.1552734375, 13.5) 
warpPedIntoVehicle(source, Vehicle) 
else 
Vehicle= createVehicle (425,1485.49, 1231.93, 10.82,0,0,180) 
end 
warpPedIntoVehicle(source, Vehicle) 
   end 
end 
addEvent ("rentV", true) 
addEventHandler ("rentV", root, rentVehicle) 
  

Posted (edited)
  
local Vehicle = {} 
function onVehicleExplode() 
      destroyElement(Vehicle[getVehicleOccupant(source)]) 
end 
addEventHandler("onVehicleExplode", getRootElement(), onVehicleExplode) 
  
local Cash = 500000 
function rentVehicle  () 
if ( getPlayerMoney ( source ) <  Cash ) then 
outputChatBox("You need 300,000$ to rent this vehicle.", source, 255,0,0) 
else 
takePlayerMoney(source, Cash) 
  
if (getElementZoneName(source) == "Los Santos International") then 
Vehicle[source]= createVehicle(425, 1924.5841064453, -2291.1552734375, 13.5) 
warpPedIntoVehicle(source, Vehicle[source]) 
else 
Vehicle[source]= createVehicle (425,1485.49, 1231.93, 10.82,0,0,180) 
end 
warpPedIntoVehicle(source, Vehicle[source]) 
   end 
end 
addEvent ("rentV", true) 
addEventHandler ("rentV", root, rentVehicle) 

Edited by Guest
Posted

Wow man, simple rules:

-Try never use events and functions with same name

-Use global constants carefully

This should work for you:

function vehicleExplodeRented() 
    if getElementData(source,'rented') then 
        destroyElement(source) 
    end 
end 
addEventHandler("onVehicleExplode", getRootElement(), vehicleExplodeRented) 
  
local Cash = 500000 
function rentVehicle  () 
    if ( getPlayerMoney ( source ) <  Cash ) then 
        outputChatBox("You need 300,000$ to rent this vehicle.", source, 255,0,0) 
    else 
        takePlayerMoney(source, Cash) 
        if (getElementZoneName(source) == "Los Santos International") then 
            local Vehicle = createVehicle(425, 1924.5841064453, -2291.1552734375, 13.5) 
            warpPedIntoVehicle(source, Vehicle) 
            setElementData(Vehicle,'rented',true,false) 
        else 
            local Vehicle = createVehicle (425,1485.49, 1231.93, 10.82,0,0,180) 
            warpPedIntoVehicle(source, Vehicle) 
            setElementData(Vehicle,'rented',true,false) 
        end 
    end 
end 
addEvent ("rentV", true) 
addEventHandler ("rentV", root, rentVehicle) 

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