Forum

> > CS2D > Scripts > Vehicle Script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Vehicle Script

5 replies
To the start Previous 1 Next To the start

old Vehicle Script

ExT
User Off Offline

Quote
Hi us

I want to ask how to make vehicle script like in |ExT| Happy Town, that has :
- Start/Stop engine
- Gear(Press F2 to gear down, Press F3 to gear up)
- Vehicle settings

Screenshot :

IMG:https://img4.imagetitan.com/img4/small/14/14_supertown_1.0_00000.jpg
edited 1×, last 23.10.16 05:40:43 am

old Re: Vehicle Script

Baloon
GAME BANNED Off Offline

Quote
Firstly, you need to learn about:
• Inserting new index into table.
table.insert(table, [pos,] value)

• Removing lastest index on table.
table.remove(table, [pos])

• ipairs looping method.
for KEY, VALUE in ipairs ( TABLE ) do

• Sine and cosine calculation.
player(id,"x")-math.sin(math.rad(player(id,"rot")-180)) [*SPEED]

player(id,"y")+math.cos(math.rad(player(id,"rot")-180)) [*SPEED]

• Image thing.
local id = image("gfx/path.png",player(id,"x"),player(id,"y"),1)


Then you might add more feature like settings and so on.
edited 1×, last 23.10.16 08:27:59 am

old Re: Vehicle Script

GeoB99
Moderator Off Offline

Quote
Besides of what user Baloon said, you need to dig the CS2D Commands/Lua list for the following hooks and Lua functions in order to implement the actions desired. At this time I'm going to help you with the prime basics:
OP has written
- Start/Stop engine

cs2d lua hook serveraction is our main hook for this task. Seeing the screenshot we'll use F4 as main button. I'll explain it in the code below.
1
2
3
4
5
6
7
function ServerActionHook(id, action)
	if ( action == 3 ) then -- The 3 value stands for F4 button in our case
		-- Start/Stop Engine code here...
	end
end

addhook('serveraction', 'ServerActionHook')
To explain what does the second line do: IF the player presses F4 the conditional code (third line) gets executed. The third line actually has a comment in it, you must replace it with an actual Start/Stop engine function code.
OP has written
- Gear(Press F2 to gear down, Press F3 to gear up)

Again we need cs2d lua hook serveraction for this. I'll use the same code like above.
1
2
3
4
5
6
7
8
9
10
11
function ServerActionHook(id, action)
	if ( action == 3 ) then -- The 3 value stands for F4 button in our case
		-- Start/Stop Engine code here...
	elseif ( action == 1 ) then -- Now the 1 value stands for F2 button
		-- Gear Down code here...
	elseif ( action == 2 ) then -- Finally the 2 value stands for F3 button
		-- Gear Up code here...
	end
end

addhook('serveraction', 'ServerActionHook')
I'm fairly sure you know the usage and its purpose of
elseif
. The fifth and seventh line must be replaced with an actual Gear function code.
OP has written
- Vehicle settings

To be honest, I don't have a clue how exactly you use G to trigger the Vehicle settings menu, can't remember. Whatever, we'll use cs2d lua hook say for that.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function SayVehicleSettings(id, message)
	if ( string.sub(message, 1, 16) == '!vehiclesettings' ) then
		menu(id, 'Vehicle Settings, ..., ..., ...')
	end
end

function VehicleSettingsMenu(id, title, button)
	if ( title == 'Vehicle Setings' ) then -- Check if the title of the menu is Vehicle Settings
		if ( button == 1 ) -- Check if the player presses the first button within the menu.
			menu(id, 'Another menu, ..., ..., ...') -- Create a subsequent menu
		-- Repeat the same thing for other buttons at your choice...
		end
	end
end

addhook('say', 'SayVehicleSettings')
addhook('menu', 'VehicleSettingsMenu')
Note that I've used also cs2d lua hook menu as to expand the menu template with various menu functions. In the third line this is our main template menu and the
...
dots must be replaced with title buttons (i.e Vehicle Lights). Afterwards, within
VehicleSettingsMenu
function you must define each button their task (i.e Turn CD Player ON -> CD Player is turned ON) or create a subsequent menu for sub functions like I did in the code.

The basics end here. For the rest it is up to you to develop the code. If you're in doubt search for a Vehicle Mod script in the File Archive or Forum and look up at the code. You'll eventually build your own idea how a Vehicle must work and its additional features.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview