PDA

View Full Version : Scripting help


Lander
04-05-2009, 06:19 PM
Hi

I'm very noob in LUA, so i'm asking for some help here.

local ClassID =
addSpawnClass("Street Racers",255,255,255,-924.072632,1050.113281,13.200515,180.0,-924.058716,1046.070435,11.8,8)
for i = 160, 171 do
addClassMember(ClassID,i,-975.841736,-353.321747,13.381999,179.083511,0,0,0,0,0,0)
end

This example it's from the main.lua, my question is:

What means the i and do in the script? Mantis told me that is a variable, but what is a variable in LUA?

Sorry for the very noob question about this =P

stodge
04-05-2009, 06:35 PM
http://www.lua.org/manual/5.1/manual.html#2.3

Happy reading!

Lander
04-05-2009, 07:49 PM
A friend told me that i stores a value, he is right??

And what about do?

(I'm from Chile, so i don't understand the english very well)

Mex
04-05-2009, 08:52 PM
'i' is a variable in this case.
A variable simply holds a value.

Example of setting up a variable called 'i' which holds the value '250':
local i = 250


'for' is a type of loop.


The main type of loop used is called a 'while loop'.
A 'while loop' simply back-to-back executes the code inside the loop until the condition becomes false.
For example, if I wanted to output 4 numbers to all players on 4 lines, without using a loop, i would do this:

outputChatBox(1, 255, 255, 255, 255)
outputChatBox(2, 255, 255, 255, 255)
outputChatBox(3, 255, 255, 255, 255)
outputChatBox(4, 255, 255, 255, 255)

Using a loop i would do this:

local i = 1
while i <= 4 do
outputChatBox(i, 255, 255, 255, 255)
i = i + 1
end

So we start off by setting up the variable called 'i' to hold a value of 1
Then in the next line we have "while i <= 4 do"
This means that lua will keep executing the code inside the loop until the value held in the variable called 'i' has a value that is greater than or equal to 4
As 1 is less than 4, lua executes the code "outputChatBox(i, 255, 255, 255, 255)" which will output 1
Then in the next line, lua adds 1 to the value held in the variable called 'i', so 'i' now holds the value '2'.
lua then checks the condition again to see if the condition is true or false,
As 2 is <= 4, lua will execute the code inside the loop again.
The code in the loop will be executed a total of 4 times.

'While loops' can check the conditions of other types of variables such as strings and boolean.


A 'for loop' is specifically for numbers, just like the example i showed above in the while loop.
An example of a for loop:

for a=160, 171 do
outputConsole(a)
end

which is exactly the same as:

local w=160
while w <= 171 do
outputConsole(w)
w = w + 1
end


and


for c=1, 300, 5 do
outputConsole(c)
end

is exactly the same as:

local p=1
while p <= 300 do
outputConsole(p)
p = p + 5
end

Lander
04-06-2009, 05:04 PM
Thanks, that i was looking for

Now i got a problem


local policiasSpawn =
addSpawnClass("Policias",255,255,255,-924.072632,1050.113281,13.200515,180.0,-924.058716,1046.070435,11.8,8) -- Create the spawn class for members to be added
for i = 1, 4 do
addClassMember(policiasSpawn,i,-975.841736,-353.321747,13.381999,179.083511,0,0,0,0,0,0) -- Add the class members to the class (look on the wiki for param details!)
end

local corredoresSpawn
addSpawnClass("Corredores Callejeros",255,255,255,-924.072632,1050.113281,13.200515,180.0,-924.058716,1046.070435,11.8,8)

addClassMember(corredoresSpawn,5,-975.841736,-353.321747,13.381999,179.083511,0,0,0,0,0,0)
addClassMember(corredoresSpawn,6,-975.841736,-353.321747,13.381999,179.083511,0,0,0,0,0,0)


In the game, all the skins (from "policias" and "corredores callejeros"), are selected in "policias", and corredores callejeros have the verceti's skin

What's wrong?

StarScream
04-07-2009, 07:59 AM
local Team1 =
addSpawnClass("Law Enforcement",255,255,0,-924.072632,1050.113281,13.200515,180.0,-924.058716,1046.070435,11.8,8)
for i = 1,2 do
addClassMember(Team1,i,-975.841736,-353.321747,13.381999,179.083511,0,0,0,0,0,0)

local Team2 =
addSpawnClass("Citizens",255,255,0,-924.072632,1050.113281,13.200515,180.0,-924.058716,1046.070435,11.8,8)
for i = 55, 66 do
addClassMember(Team2,i,-975.841736,-353.321747,13.381999,179.083511,0,0,0,0,0,0)
end

This seems to work for me, give it a try.

Change the Numbers after"i" to your Skins Models.

poponorto
04-07-2009, 10:17 AM
warum sind meine autos nicht gespeichert da wo ich sie speicher immer wen ich /savecar ID mach dan speichert er sie aber die gehn dan wek

Lander
04-07-2009, 07:19 PM
I've fix the problem, now iv'e got other problem:

function iniciarJuego (playerID)

if isPlayerSpawned ( playerID ) then
local ( playerID )
setPlayerPos ( playerID, -999.31647576925, -866.44807988325, 12.60466003418 ) else
putPlayerInVehicle ( PlayerID, 141, 2 )
end
end


I want that someone who is spawned in Vice City, spawn on that coordinates, with that vehicle, on the driver seat. And that all i've got.

(Really, i want a register/login system, when someone register in the server, appears on thar coordinates to buy a car)

Mantis
04-08-2009, 09:07 PM
function iniciarJuego (playerID)

if isPlayerSpawned ( playerID ) then
local ( playerID )
setPlayerPos ( playerID, -999.31647576925, -866.44807988325, 12.60466003418 ) else
putPlayerInVehicle ( PlayerID, 141, 2 )
end
end

I would do it slightly different there. Here is what I've quicky just wrote, not sure if it works, I've not tested it.

This is on player spawning, after spawning, they will goto the co-ords.
function iniciarJuego (playerID)

onPlayerSpawn(playerID)
setPlayerPos(PlayerID,-999.31647576925,-866.44807988325,12.60466003418)
delay(500)
putPlayerInVehicle(PlayerID,141,2)
end
end

If you want it to do that after a player is spawned (Not sure if you want a command like /Juego) or if you want it to automatically check, if you want it to check, then you'd have to do it differently. Lemme know how you want it?, is it for all players?,want it a timed check?

Lander
04-10-2009, 02:31 PM
I've got this (like you tell me on the server)

function iniciarJuego (playerID)

onPlayerSpawn(playerID)
setPlayerPos(playerID,-999.31647576925,-866.44807988325,12.60466003418)
createVehicle ( 141, -999.31647576925,-866.44807988325,12.60466003418, 26, 255, 255 )
putPlayerInVehicle(playerID,141,1)
end

addCommand ("test","iniciarJuego")

And doens't work.

Mantis
04-10-2009, 10:20 PM
Ah no. You need to use createVehicle before you run the function. You'll need to know it's exact vehicleID(place in the script) if you place it at the top of your other cars, it'll become ID1

Try this.

createVehicle(141, -999.31647576925,-866.44807988325,12.60466003418, 26, 255, 255 ) -- You'll need to find the ID of this vehicle for the next part. Add it above all your other vehicles to make it ID1

function iniciarJuego (playerID)

onPlayerSpawn(playerID)
setPlayerPos(PlayerID,-999.31647576925,-866.44807988325,12.60466003418)
delay(500)
putPlayerInVehicle(PlayerID,1,2)
end
end

Lander
04-10-2009, 11:42 PM
Sorry, doens't work, but don't worry, i will find a way to make my gamemode playable

And i got another problem, but now with the client

I added a checkpoint and an actor on sunshine autos, and when tried to enter to my server, the client crashes

actorID = 1 createStaticActor(171,-1025.343506,-854.521912,13.089783,205.278061, false)
markerID = 1 createGlobalCheckpoint (-1024.836670,-855.595947,13.090864, 10)

Mantis
04-11-2009, 09:03 AM
actorID = 1 createStaticActor(171,-1025.343506,-854.521912,13.089783,205.278061, false)
markerID = 1 createGlobalCheckpoint (-1024.836670,-855.595947,13.090864, 10)

Remove actorID = 1 and markerID = 1 then try again.
createStaticActor(171,-1025.343506,-854.521912,13.089783,205.278061)
createGlobalCheckpoint(-1024.836670,-855.595947,13.090864,5)

I think the size of the checkpoint is 5max (Not sure, so try that)

Lander
04-12-2009, 12:02 PM
the client stiil crashing, i will post the bug on the forums

Mantis
04-12-2009, 04:37 PM
If a player crashes still crashes even if you have the createGlobalCheckpoint and createStaticActor, it's not the problem. Something else must be crashing it.

Lander
04-12-2009, 06:52 PM
Well, the createStaticActor is crashing the server, why?

Because i was creating the actor in the server with VLE, and the code was (according to the code on the wiki)

createStaticActor (14, -1034.7280366868, -853.96064942814, 13.085195541382, -119.90543365479, true, none, Muscle Cars)

I put this code on the other server, and what happend??? The client doens't crashed, but the actor doesn't appear.

Mex
04-12-2009, 07:20 PM
In VLE the lines stored in the Actors.txt file aren't the same as the paramters to use for the function.
(This is because the actor's name and animation is stored on the same line, and these are seperate functions)


local ActorID = createStaticActor (14, -1034.7280366868, -853.96064942814, 13.085195541382, -119.90543365479, true)
setStaticActorName(ActorID, "Muscle Cars")

Note:
You must put quotation marks or apostrophes around strings.
On the vco wiki it should say the parameter type before the parameter name, like here: http://wiki.gtagaming.com/Static_Actor_Functions/s etStaticActorName
(In the Syntax line)

Lander
04-12-2009, 08:32 PM
Thanks Mex, i will kept in mind that

I have made my first command for VCO, a /lock and /unlock car. Horray!!!!!!!

But the problem is the all the players can saw the outputChatBox when someone type the code. How i can make this local????

Here is the code

function carLock(PlayerID)

local VehicleID = getPlayerVehicleID(PlayerID)

if isPlayerInAnyVehicle (playerID) == 1 then
setVehicleLockedState(VehicleID, 1)
outputChatBox("Car Locked",255,0,0,255)
end
end

addCommand ("lock", "carLock")

function carUnlock(playerID)

local VehicleID = getPlayerVehicleID(PlayerID)

if isPlayerInAnyVehicle (playerID) == 1 then
setVehicleLockedState(VehicleID, 0)
outputChatBox("Car Unlocked",255,0,0,255)

end
end

addCommand ("unlock", "carUnlock")

Mantis
04-12-2009, 08:46 PM
Thanks Mex, i will kept in mind that

I have made my first command for VCO, a /lock and /unlock car. Horray!!!!!!!

But the problem is the all the players can saw the outputChatBox when someone type the code. How i can make this local????

Here is the code

That is quite simple Lander, you just need to identify who sees the message, examples as follows:

outputChatBox("Hello World!",255,0,0,255)

That echos the phrase "Hello World" to the entire server.

outputChatBox(PlayerID,"Hello World!",255,0,0,255)

That echos the phrase "Hello World!" to the player who performs the command.

There are variations of who see's the text (Server-wide, single player or even someone who the player aimed the command at, such as /pm)

The Syntax for outputChatBox is:
outputChatBox( PlayerID / Server-wide (leave blank for that), "Message with quotation marks", r,g,b,o)

Your command would be (I'm pretty sure you'll grasp what I'm talking about when you compare yours to mine, if you haven't already)

function carLock(PlayerID)

local VehicleID = getPlayerVehicleID(PlayerID)

if isPlayerInAnyVehicle (playerID) == 1 then
setVehicleLockedState(VehicleID, 1)
outputChatBox(PlayerID,"Car Locked",255,0,0,255)
end
end

addCommand ("lock", "carLock")

function carUnlock(PlayerID)

local VehicleID = getPlayerVehicleID(PlayerID)

if isPlayerInAnyVehicle (playerID) == 1 then
setVehicleLockedState(VehicleID, 0)
outputChatBox(PlayerID,"Car Unlocked",255,0,0,255)

end
end

addCommand ("unlock", "carUnlock")

Lander
04-12-2009, 08:49 PM
Thanks Mantis, I will increase your reputation level (if i can =P)

Edit:

I'm checking the wiki, and there's no info that i need for my script, so i'm asking here.

I need the parameters of "onPlayerEnterGlobalMarker", please

Mantis
04-13-2009, 08:25 PM
onPlayerEnterGlobalMarker ( playerID PlayerID, integer MarkerID integer Type )

Thats the syntax, I've made the page on wiki if you wish to look.

Lander
04-14-2009, 04:38 PM
I cna't do it, the outputChatBox doesn't show, also, the marker disspaeared.

function checkpointFunction (playerID)
markerID = 1 createGlobalCheckpoint (-1033.797119,-854.637634,13.085196,1.5)
if onPlayerEnterGlobalMarker (playerID, 1, checkpoint) == 1 then
outputChatBox (playerID, "testing", 255,255,0,255)
end
end


/me invokes Mantis =P

Mex
04-18-2009, 07:01 PM
yo try this:


createGlobalCheckpoint(-1033.797119, -854.637634, 13.085196, 1.5)
function onPlayerEnterGlobalMarker(PlayerID, MarkerID, MarkerType)
outputChatBox(PlayerID, "testing", 255, 255, 0, 255)
end


If you want to check if the player entered that particular marker, you could do:


local MarkerIDTest = createGlobalCheckpoint(-1033.797119, -854.637634, 13.085196, 1.5)
function onPlayerEnterGlobalMarker(PlayerID, MarkerID, MarkerType)
if MarkerID == MarkerIDTest then
outputChatBox(PlayerID, "testing", 255, 255, 0, 255)
end
end

Lander
04-18-2009, 08:16 PM
Thanks dude, you save me

Now the problem is the next:

I've made a command to troggle the player Controllable (i add this in the code when someone enter to the checkpoint), but when i type the code, the server crashed

The problem is the server or the server????

local MarkerIDTest = createGlobalCheckpoint(-1033.797119, -854.637634, 13.085196, 1.5)
function onPlayerEnterGlobalMarker(PlayerID, MarkerID, MarkerType)
togglePlayerControllable ( playerID, 0 )
if MarkerID == MarkerIDTest then
outputChatBox(PlayerID, " Tenemos los siguientes vehiculos a la venta ", 255, 255, 0, 255)
outputChatBox(PlayerID, " Para comprar un vehiculo, escribe /comprar <nombre vehiculo> ", 255, 255, 0, 255)
end
end

function onPlayerExitGlobalMarker (playerID, markerID, markerType)
local MarkerIDTest =
trogglePlayerControllable ( playerID, 1 )
if MarkerID == MarkerIDTest then
outputChatBox(PlayerID, " Vuelva pronto a Sunshine Autos!", 255, 255, 0, 255)
end
end

addCommand ("exit", "onPlayerExitGlobalMarker")

Xeonon
04-18-2009, 08:58 PM
trogglePlayerControllable ( playerID, 1 )\


Change that to this.


togglePlayerControllable( playerID, 1)

Lander
04-18-2009, 09:21 PM
thanks, but the server still crashing

Mex
04-19-2009, 08:51 AM
try this

local MarkerIDTest = createGlobalCheckpoint(-1033.797119, -854.637634, 13.085196, 1.5)
function onPlayerEnterGlobalMarker(PlayerID, MarkerID, MarkerType)
if MarkerID == MarkerIDTest then
togglePlayerControllable ( PlayerID, 0 )
outputChatBox(PlayerID, " Tenemos los siguientes vehiculos a la venta ", 255, 255, 0, 255)
outputChatBox(PlayerID, " Para comprar un vehiculo, escribe /comprar <nombre vehiculo> ", 255, 255, 0, 255)
end
end

function onPlayerExitGlobalMarker(PlayerID, MarkerID, MarkerType)
if MarkerID == MarkerIDTest then
togglePlayerControllable ( PlayerID, 1 )
outputChatBox(PlayerID, " Vuelva pronto a Sunshine Autos!", 255, 255, 0, 255)
end
end

Mantis
04-23-2009, 09:56 PM
Bumped - Not sure if it's just me, but it says Lander posted last, I'm not sure if Lander got Mex's fix.

Lander
04-24-2009, 02:24 PM
Bumped - Not sure if it's just me, but it says Lander posted last, I'm not sure if Lander got Mex's fix.

Don't worry, i got the fix :wink2: