Jump to content

[NEED HELP] Choose ramdom pos


armyOFshadows

Recommended Posts

hello dear ,every body who read this topic

 

there  i have create script for spawn fire for firedept as i say to you

first array positions as
 



	function setfire (commandName,size)
	local rpos = {{0,0,3.5},{3,3,3.5},{5,5,3.5}}
	 for i = 1, 3 do
	 createFire(myrandomvar,(size))
	 end
     outputChatBox ("fire start in pos "..x.."")	
    end
addCommandHandler("fire",setfire)

i have look on topics and see a few tips like use math.random() or table , but  cant undrestand enough them.

help me for this situation ?

Link to comment

I can't really understand what you actually want to do? 

If you want to set fire in the given locations( inside that table) and u want a timer for that so that it reapeats the same action every "x" moment, you should use setTimer for ur function. And get rid of the commandHandler, you don't need that for automatic functions(timer).

Also i'm not sure about the arguments you've given to the createFire function.

Also about the loop. You can use #rpos instead of manually writing what's inside the table.

local rpos= {
    {x= 0, y= 0, z=0}
}
setTimer(function(),
for i=1, #rpos do
   createFire(rpos[i].x,rpos[i].y,rpos[i].z,and u specify the size using the wiki instead of the command)
outputChatBox("Fire started at "..rpos[i].x.." "..rpos[i].y.." "..rpos[i].z,root,r,g,b)
end
end)
Edited by ๖ۣۜζ͜͡RapGod
  • Like 2
Link to comment

hi

thank you for answering,

its firsts part of fire dept script i want to create, and in my mind a function must be there for spawn fire in a random position of my wichs we add there to function,
then fire spawned in one of 3 or 5 or #? location we set before and you know it marker and chats after it start to tell fd.its all prob around choose one pos from all poses i want give there, so fire every time spawn in one of positions we set.the fire command is for test too, i will delete it and changed by auto function later

Link to comment
1 hour ago, armyOFshadows said:

hi

thank you for answering,

its firsts part of fire dept script i want to create, and in my mind a function must be there for spawn fire in a random position of my wichs we add there to function,
then fire spawned in one of 3 or 5 or #? location we set before and you know it marker and chats after it start to tell fd.its all prob around choose one pos from all poses i want give there, so fire every time spawn in one of positions we set.the fire command is for test too, i will delete it and changed by auto function later

If u want to get a random position off the table then u dont need a loop. Instead u can use this:

local rpos ={
  [1]={ x = 0, y=0, z=0},
  [2]={ x=1, y=1, z=1}
  }

setTimer(function()
    local randomPicker= rpos[math.random(1,2)]
    createFire(randomPicker.x,randomPicker.y,randomPicker.z, the size here)
    outputChatBox("Fire started at "..randomPicker.x.." "..randomPicker.y.." "..randomPicker.z, root,255,0,0)
end, time in milliseconds)

 

  • Like 1
Link to comment
12 minutes ago, ๖ۣۜζ͜͡RapGod said:

If u want to get a random position off the table then u dont need a loop. Instead u can use this:

local rpos ={
  [1]={ x = 0, y=0, z=0},
  [2]={ x=1, y=1, z=1}
  }

setTimer(function()
    local randomPicker= rpos[math.random(1,2)]
    createFire(randomPicker.x,randomPicker.y,randomPicker.z, the size here)
    outputChatBox("Fire started at "..randomPicker.x.." "..randomPicker.y.." "..randomPicker.z, root,255,0,0)
end, time in milliseconds)

 

oh with this simple example i know how to use math.random exact,and thank you.
and about loop, i need it for spawn bigger fire(not so big).

and why we use it on a timer func?
 

Link to comment
8 minutes ago, armyOFshadows said:

oh with this simple example i know how to use math.random exact,and thank you.
and about loop, i need it for spawn bigger fire(not so big).

and why we use it on a timer func?
 

Well i'm using a timer function so that the fire occurs by itself after some time has passed. Just so u don't have to type it manually.

You dont need a loop to spawn a bigger fire. You can just use the size argument inside the createFire function after specifying the x y z of that fire.

Check out how it's used(arguments):

https://wiki.multitheftauto.com/wiki/CreateFire

Edited by ๖ۣۜζ͜͡RapGod
  • Like 1
Link to comment
1 minute ago, ๖ۣۜζ͜͡RapGod said:

Well i'm using a timer function so that the fire occurs by itself after some time has passed. Just so u don't have to type it manually.

You dont need a loop to spawn a bigger fire. You can just use the size argument inside the createFire function after specifying the x y z of that fire.

tell me if you have any discord or ts for talk or chat,i cant send pm there

 

i test it to see what gone diffrent with timer func

Link to comment
1 hour ago, ๖ۣۜζ͜͡RapGod said:

If u want to get a random position off the table then u dont need a loop. Instead u can use this:

local rpos ={
  [1]={ x = 0, y=0, z=0},
  [2]={ x=1, y=1, z=1}
  }

setTimer(function()
    local randomPicker= rpos[math.random(1,2)]
    createFire(randomPicker.x,randomPicker.y,randomPicker.z, the size here)
    outputChatBox("Fire started at "..randomPicker.x.." "..randomPicker.y.." "..randomPicker.z, root,255,0,0)
end, time in milliseconds)

 

good, setTimer  handle loop time too 

now i can work for more items i need.

thank you

  • Like 1
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...