lopexsw

Need some help with scripting.

Recommended Posts

Okay so I just very, very recently got into scripting in general. I'm very interested in it and I already followed the first page of the scripting wiki and made the car spawner command.

The thing I next want to make is a car fixing/washing spot. I don't plan to download just a recource and have it done, my aim is to do it, but learn the stuff along the way.

So as much as I know:

bool fixVehicle ( vehicle theVehicle )

That is the function to fix a vehicle, but how can I make this into a command that will fix a vehicle in a certain place in a certain amount of time.

For example: You drive your damaged car into a pay'n'spray and then whait a couple of seconds and it fixes the car for you.

That would be my end goal with this, but as I already mentioned I want to learn along the way!

Share this post


Link to post
14 minutes ago, lopexsw said:

You drive your damaged car into a pay'n'spray

First of all you have to open the garage's of Pay'n'Spray. You need setGarageOpen for that. The easiest way to recognize if vehicle is there you can simply create markers (createMarker) inside Pay'n'Spray.
 

16 minutes ago, lopexsw said:

whait a couple of seconds

setTimer
 

Share this post


Link to post

So I understand the steps are these:

 

  • When you drive in the marker recognizes if a vehicle is inside
  • Display message to the player if he drove in like "Welcome to Jacks repair shop, wait a couple of seconds for your ride to get all fixed up."
  • Start a countdown or something similar (Not visible to the player) and then fix the car via fixVehicle but only inside the marker not all map or something.
  • When the car if fixed display message "Thank you for coming to Jacks repair shop!"
  • Charge a certain amount of money at the same time as the message gets displayed.

Okay, I decided to remove the garage door in general, it's not required..

It seems more understandable in steps what to do now, but I still have a few questions:

1. Okay so you create the marker via lua script in your resources, but how do you make it invisible? Most likely I will place a Checkpoint marker, it needs to be invisible and then have a sense of when a car comes in or some cmd, that tests if someone drove in and then gives a true/false answer, thus making it fix the vehicle inside the checkpoint.

2. How do you make the fixVehicle only fix the persons car that is inside the invisible marker? Would it follow something along the lines of getting the source of the true/false (aka the player) then fixing his vehicle?

3. Oh and if a player drives in the marker wouldn't it disapear? We don't want that :P

Edited by lopexsw
Added a nother question.

Share this post


Link to post

To make the marker invisible, you'd probably just want to set its alpha to 0. The marker itself won't be destroyed by itself when a player enters it, so you don't have to worry about that.

What you want to do is attach an event handler to onMarkerHit attached to the marker element, then check whether hitElement is a vehicle or not and whether there is a driver (otherwise you can't charge him). The next thing would be to set a timer (store the variable in a table like timers[hitElement]) to a function which would fix the vehicle and charge the driver (make sure to check whether the car still has a driver after the timer elapses). As soon as onMarkerLeave it triggered on that market element, you'll want to killTimer(timers[leftElement]) (you'll probably want to check if it isTimer as elapsed timers give out warnings when you try to kill them).

Edited by MrTasty

Share this post


Link to post

Okay so i used a pre-made script, that is similar to what I'm making, but a bit different. I tried to only make the idlewood pay'n'spray, so I changed a few commands and this is my garage spraying script:

fixMarker = createMarker (2062, -1831.69739, 12.18634,"cylinder", 4, 0, 0, 0, 255)
fixBlip = createBlip(2062.00781, -1831.69739, 12.18634,63,2)

function fix(thePlayer)
veh = getPedOccupiedVehicle(thePlayer)
outputChatBox ("Welcome to Jacks repair shop! Please wait while we fix up your car!", thePlayer, 127, 127, 0)
if getElementHealth(veh) < 999.0 and (getPlayerMoney(thePlayer)) > 1001.0
then price = 1001.0
takePlayerMoney(thePlayer, price)
fixVehicle(veh)
setElementFrozen(veh, true)
setTimer(setElementFrozen, 6000, 1, false)
outputChatBox( "Your vehicle has been fixed for 1000$, come back again!", thePlayer, 127,127,0)
else
outputChatBox("You don't have enough money to pay for the services!",thePlayer,127,127,0)
end
end
addEventHandler("onMarkerHit",fixMarker,fix)

So that is what I have gotten so far. Making a marker inside the pay'n'spray, then makeing a Blip on the map where it is.

Then I got the check for the car if it has a player inside it. Then it says the msg. Then if the car is under max health and the player has over 1k money, then it takes the money (price=1001.0) and fixes the vehicle, while also freezing it for 6 seconds.

Then it says the msg, otherwise if the "if" turns out false, then it outputs the false msg.

 

Now the biggest problem I ran into is actually testing my script on my own server, since there is a garage door there. I have tried literally everything, so what I turned out to do is copy the wiki's guide on how to open/close a garage door! I placed the id in, but I got confused with:

  1. The garage doors x,y,z coords.
  2. The block thingys sizes..(Collision shapes)

This is the end result of my other script for the garage door.

GARAGE_ID = 8

-- create a collision shape and attach event handlers to it when the resource starts
addEventHandler("onResourceStart", getResourceRootElement(),
function (resource)
	local garageCube = createColCuboid(2050, -1828, 0,15, 15, 15)
	addEventHandler("onColShapeHit", garageCube, onGarageCubeHit)
	addEventHandler("onColShapeLeave", garageCube, onGarageCubeLeave)
end)

-- open the door when someone enters the garage's collision shape
function onGarageCubeHit(hitElement, matchingDimension)
	if (getElementType(hitElement) == "player") then
		-- check to make sure the door is closed
		if (not isGarageOpen(GARAGE_ID)) then
			-- open the door
			setGarageOpen(GARAGE_ID, true)
		end
	end
end

-- close the door when someone leaves the garage's collision shape
function onGarageCubeLeave(leaveElement, matchingDimension)
	if (getElementType(leaveElement) == "player") then
		-- check to make sure the door is open
		if (isGarageOpen(GARAGE_ID)) then
			-- close the door
			setGarageOpen(GARAGE_ID, false)
		end
	end
end

This garage door is a individual script that I made aside from the garage script itself, but I'm not sure what does it go under. The garage door script goes under "Map" in the meta.xml file, but I don't know what does the garage door go under, so I  just placed "Map" in that scipts meta.xml too..

So the problems I feel I'm facing currently:

  1. Making the meta.xml files, since I'm not sure what script ideas go under what category type. For ex: Gamemode or map.
  2. Placing the coords x,y,z of the collision boxes for the open garage door script.

Possibly something more, but I can't remember right now.

I would really, really appreciate if you cool guys could help me with these problems.

Share this post


Link to post

Don't worry about author, game mode etc attributes you don't need them. As long as your scripts are referenced in the meta.xml along with your files, it will be fine.

 

If you look at the garage functions on the wiki you will see the link for the garage ID's and positions then you can just go to that position, use the command "gp" (if you're running freeroam) that will show your current position.

Share this post


Link to post
38 minutes ago, pa3ck said:

If you look at the garage functions on the wiki you will see the link for the garage ID's and positions then you can just go to that position, use the command "gp" (if you're running freeroam) that will show your current position.

Whell, the gp doesn't work, but I'm not sure what you mean by "If you're running freeroam" Cause I literally am just running the server, I haven't messed with the servers options yet or auto loading resources.

Thanks on the info about the meta files, that helped. I'm currently messing around with the numbers to try to get it to work... No luck so far.

Edit: Okay, I have no freaking idea what I'm doing wrong, but it just won't work :(

Edited by lopexsw
Sadness

Share this post


Link to post

Freeroam is the name of the game mode that games with mta. If you press F1 you should see your x,y,z position as well.

Share this post


Link to post
6 hours ago, lopexsw said:

(getPlayerMoney(thePlayer)) > 1001.0

Small tip:
You can use ">= 1000" instead of "> 1001". It will mean if player has equal or more than 1000$

Share this post


Link to post
6 hours ago, Bananovy said:

Small tip:
You can use ">= 1000" instead of "> 1001". It will mean if player has equal or more than 1000$

Thank you, but how the hell do I fix that garage door??? Help!

Also since I haven't changed anything from what  you said I should be in freeroam, but I don't have anything on F1 and the "gp" or "/getpos" or anything along those lines doesn't show my coordinates. (I have the newest version of the game)

Edited by lopexsw
Sadness once again.

Share this post


Link to post
2 hours ago, lopexsw said:

Thank you, but how the hell do I fix that garage door??? Help!

Also since I haven't changed anything from what  you said I should be in freeroam, but I don't have anything on F1 and the "gp" or "/getpos" or anything along those lines doesn't show my coordinates. (I have the newest version of the game)

Write /start freeroam in chat. Maybe you're not in freeroam idk. 

Share this post


Link to post

IT WORKED! Thank you guys! You are the best! I will most likely soon, make a new post, thus continueing my learning!

Thank you alot for this! The script works exactly, like I want it to!

Mods can lock this :)

Edited by lopexsw

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.