lopexsw

Lopex's 3rd scripting attempt!

Recommended Posts

So hello everyone it's me, Lopex, once again!

Today I have thought of something new I can try to make! It's a mower job!

The idea is that a player goes to some mowers that would be spawner in Glen Park, then get on them and have a option like /startmowing in chat, then when they do such command they get told in chat to start driving around, and as they drive around Glen Park they would have a little bar on their screen that fills up and when it's full it goes away and gives you some money!

So steps that I believe will be required:

  • Spawn the vehicle via spawnVehicle (coords, rotation)
  • After spawning the vehicle we check if the player is in that vehicle
  • If it's a mower then you get the option in chat, if not then nothing
  • After player does the certain command they start mowing and are required to drive around.
  • It displays a little bar that fills up as they drive
  • When set bar is full, they recieve a certain amount of money! (Doesn't get affected by speed or vehicle hp!!!)
  • Displays the option to start mowing again.

So.. The thing I am confused about is weather to use spawnVehicle or createVehicle... Like what is the difference? I want the mower to be there all the time, not by set event, so mabey we want to do onResourceStart ? Or can we just do a cmd like spawnVehicle or createVehicle alone, without any event or anything, just at the top of the script?

Also I got confused by one more thing.. If let's say I do something like:

function spawnMower(--what do I place here?) --And I don't mean only on the event "onResourceStart" I mean like overall what do I place there?
addEventHandler(onResourceStart, getRootElement(), spawnMower)

As I say it there... What do I place in those () brackets? Does it work like: Since I have onResourceStart (Which doesn't have any arguments) I don't need to place anything there? But if it let's say had something with like 2 arguments, then I need to place those there?

Someone please help me out with my questions and remember! THE AIM IS FOR ME TO LEARN NOT TO GET A FINISHED SCRIPT FAST!

I will make a mini-script as far as I think I can take it. When I get home that is.

Thanks for all your patience to read this and thanks if you replied in any, shape or form!

Share this post


Link to post

If you look at spawnVehicle you can see it expects a vehicle element. Now, when you want to create a vehicle you wouldn't have the vehicle element, so they are not the same functions. You will need to use createVehicle.

Yes, you would leave the parameters blank at the onResourceStart event. But make sure you have resourceRoot which is short for getResourceRootElement(getThisResource()) because if you leave it as root (short for getRootElement()) it will be fired whenever a resource starts, not just that single one. 

What else do you put there? Well, you want to create vehicles, that function is the right place to create vehicles.

After you created that function, create a command which will check if the player vehicle model is the same as the mower model then create the GUI etc. But I would leave out the GUI, try to implement the checkpoint system first.

 

Event names are always strings, make sure you put them like "onResourceStart" etc

Edited by pa3ck

Share this post


Link to post
function spawnMower()
	createVehicle( 572, -- will edit when time
	end
end
addEventHandler ( "onResourceStart", resourceRoot(), spawnMower )

function giveoptions( thePlayer, seat, jacked)
	if getElementModel(getPedOccupiedVehicle( thePlayer )) ~= 572 then return end --if not in mower then just stop!
		if (getElementModel (source) == 572) then
			outputChatBox( "Do /startmowing to start mowing the grass!", getRootElement(), 10,255,0, false)
		end
	end
addEventHandler('onVehicleEnter', root, giveoptions)

function mowing(thePlayer)
outputChatBox("Drive through the red checkpoints to mow the grass!", getRootElement(),10,255,0,false)

addCommandHandler("startmowing", mowing, false, false)

Okay, I had some free time, this is what I got, obviously if you can point out some mistakes and things that I should to, to improve the script!

So problems I faced and didn't really quite know what to do in:

function mowing(thePlayer)
outputChatBox("Drive through the red checkpoints to mow the grass!", getRootElement(),10,255,0,false)

addCommandHandler("startmowing", mowing, false, false)

1. What do I place in the "Function mowing ()" brackets? I was quite confused here, since it's not just a event handler where you place the events arguments.

2. In my opinion (without any help yet) I got to the part, where I need to place checkpoints. I want to place 1 checkpoint then when the player with his mower drives in it, make it disapear and make a new one somewhere else.

Share this post


Link to post
function giveoptions( thePlayer, seat, jacked)
	if getElementModel(getPedOccupiedVehicle( thePlayer )) ~= 572 then return end --if not in mower then just stop!
		if (getElementModel (source) == 572) then
			outputChatBox( "Do /startmowing to start mowing the grass!", getRootElement(), 10,255,0, false)
		end
	end
addEventHandler('onVehicleEnter', root, giveoptions)

-- Change it to this cause you are checking twice even though you already checked the element model once
-- Also i've added the possibility to add several vehicles within this script in a table

local AllowedVehicle = { 572 }
-- To add more Vehicles fill in the following things in the AllowedVehicle Table AllowedVehicle = { ID, ID, ID, ...}

function giveoptions( thePlayer, seat, jacked)
	local VehicleID = getElementModel(getPedOccupiedVehicle( thePlayer ))
		for i, v in pairs (AllowedVehicle) do
			if VehicleID == v then
				outputChatBox( "Do /startmowing to start mowing the grass!", thePlayer, 10,255,0, false)
			else return end
		end
end
addEventHandler('onVehicleEnter', root, giveoptions)

Hope you like this and does it works because i'm writing this on my phone and not testing it :P 

Edited by Syntrax#

Share this post


Link to post
3 hours ago, Syntrax# said:

function giveoptions( thePlayer, seat, jacked)
	if getElementModel(getPedOccupiedVehicle( thePlayer )) ~= 572 then return end --if not in mower then just stop!
		if (getElementModel (source) == 572) then
			outputChatBox( "Do /startmowing to start mowing the grass!", getRootElement(), 10,255,0, false)
		end
	end
addEventHandler('onVehicleEnter', root, giveoptions)

-- Change it to this cause you are checking twice even though you already checked the element model once
-- Also i've added the possibility to add several vehicles within this script in a table

local AllowedVehicle = { 572 }
-- To add more Vehicles fill in the following things in the AllowedVehicle Table AllowedVehicle = { ID, ID, ID, ...}

function giveoptions( thePlayer, seat, jacked)
	local VehicleID = getElementModel(getPedOccupiedVehicle( thePlayer ))
		for i, v in pairs (AllowedVehicle) do
			if VehicleID == v then
				outputChatBox( "Do /startmowing to start mowing the grass!", thePlayer, 10,255,0, false)
			else return end
		end
end
addEventHandler('onVehicleEnter', root, giveoptions)

Hope you like this and does it works because i'm writing this on my phone and not testing it :P 

I appreciate it really much, but this part is completely new to me and I didnt understand non of it...

local VehicleID = getElementModel(getPedOccupiedVehicle( thePlayer ))
		for i, v in pairs (AllowedVehicle) do
			if VehicleID == v then

The I and V and pairs are like wtf? Can u please explain or just make it less efficiant, but easier to understand..

Share this post


Link to post

@lopexsw, I could teach you some basic lua in real time with Kobra.io if you want so you can make your script. It won't be hard, I will teach you the pure basics which should help you get started more easily. I can even guide you through the process of making this script that you want, as well as teach you some stuff about tables and how to loop through them like Syntrax showed you. I sent you a PM with a discord link so we can arrange when you want to get started. Let me know if you're interested. I think it will be fun :)

Edited by Tails

Share this post


Link to post

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.