Jump to content

I'm new in Lua, need some help to start


Recommended Posts

Hi all, I started today to learn Lua, I know Pawn, PHP, Javascript and a little of C++.

I have 2 problems. I tried to increase the damage of the weapons, especialy M4, with OnPlayerDamage and setElementHealth, and failed. I'd like some example with how to do a random spawn.

Link to comment

Hi there and welcome, you made the smartest decision of your life :D.

Well you should show us the script so we can help.

and here is how to pick a random spawn (make a table of them) and then use:

local Spawns = { 
{0, 0, 0}, -- 0, 0, 0 are the coordinates of the spawn position 
{1, 1, 1}, 
{2, 2, 2}, 
--etc 
{5, 5, 5} 
} 
addEventHandler('onPlayerJoin', root, --When the player joins 
function() 
local x, y, z = unpack(Spawns[math.random(#Spawns)]) 
spawnPlayer(source, x, y, z) 
end 
) 

And read this : http://lua-users.org/wiki/TablesTutorial

Edited by Guest
Link to comment
local mySpawnTable = { 
{-1285, -34, 15},  
{1809, -2477, 14}, 
} 
  
addEventHandler("onPlayerJoin",root, 
function () 
local ran = math.random(#mySpawnTable) 
local x, y, z = mySpawnTable[ran][1], mySpawnTable[ran][2], mySpawnTable[ran][3] 
spawnPlayer(source, x, y, z) 
end) 

This will spawn the player in a random between Los Santos airport and San Fierro airport when they join.

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