Jump to content

Variable + int math?


Recommended Posts

  • Moderators

The problem with your script was that local data won't exit the function.

local cars = 0 
function onenter (player) 
  cars = cars+1 --local cars = cars+1[/color] 
  outputChatBox (cars, root) 
end 
addEventHandler ("onVehicleEnter",root,onenter) 

local A = 0

if A then

> local A = A +1 -- local will not exit

> outputChatBox(A) -- in the chatbox you will see "1" because it is in the function.(local)

end

outputChatBox(A) -- in the chatbox you will see "0"

Try the function/event of denny, it is the best/fastest sample.

Link to comment

Works thank now I have another querstion

When somebody is sitting on a f.aggio from the table noobf.aggios respawnVehicle he will be warped to the spawnpoint how i can make that only the f.aggios which are empty will be respawned?

Code:

local noobf.aggios = { 
[f.aggio1]=true, 
[f.aggio2]=true, 
[f.aggio3]=true, 
... 
} 
  
  
function respawnF.aggiosAdmin () 
    for allf.aggios, index in pairs ( noobf.aggios ) do 
respawnVehicle (allf.aggios) 
        end 
    end 
addCommandHandler ("f.agg", respawnF.aggiosAdmin) 

Sorry for "." it will be identified as an cuss?

Link to comment
  • Moderators

hhhhmmm first check your syntax.

  
local noobf.aggios = { 
f.aggio1, 
f.aggio2, 
f.aggio3 
--... 
} 
  
  
for index, allf.aggios in pairs (noobf.aggios)do -- index is left, not right. 
  if isElement (allf.aggios) then  
  -- some vehicles can be delete by adminpannel(or something else) you will get errors/warnings. Check with isElement(). 
  respawnVehicle (allf.aggios) 
  end 
end 

I will not recommend you to use "." between normal value's, but I leave the script for what it is. and no I don't know what you mean.

Check if people are inside:

https://wiki.multitheftauto.com/wiki/Ge ... eOccupants

Link to comment

Better, use

getVehicleOccupant 

Then it will look something like this:

  
local noobf.aggios = { 
[f.aggio1]=true, 
[f.aggio2]=true, 
[f.aggio3]=true, 
... 
} 
  
  
function respawnF.aggiosAdmin () 
    for allf.aggios, index in pairs ( noobf.aggios ) do 
driver = getVehicleOccupant ( allf.aggios ) 
if not ( driver ) then 
respawnVehicle (allf.aggios) 
        end 
    end 
end 
addCommandHandler ("f.agg", respawnF.aggiosAdmin) 

(BTW, why not store the vehicles which are created in a table, it's much easier.)

for example:

dannycar = {} 
dannycar[ playerelement ] = createVehicle ( ... ) 

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