YSI:Basic Example Mode

From SA-MP Wiki

Jump to: navigation, search

Introduction

For this example we are going to first convert the LVDM mode which comes with the server to YSI and then update it to the LVDM mode with properties, banks and ammunations (aka LVDM-Land Grab). This is an exercise to show how simple to use YSI is, how similar to normal SA:MP coding it is and yet how much more powerful it is.

Starting

We are going to write this from scratch using the existing mode as a guide. First open pawno twice, in one open the LVDM which comes with the server, in the other start a new file:

Image:Two_pawnos.jpg

I wouldn't recommend coding like that though, very difficult to see.

The new file should be using YSI (if it's not you've gone wrong somewhere in the installation). In the LVDM pawno scroll down to OnGameModeInit near the bottom, it should have loads of AddPlayerClass and AddStaticVehicle lines. Do a find and replace on AddPlayerClass, converting them to Class_Add, so you now have loads of Class_Add lines. Vehicles don't need modification, the few pickups do but they're a little more complicated. Class_Add and AddPlayerClass have the same parameters (or near enough, Class_Add can take more weapons), however Pickup_Add and AddStaticPickup don't use the same parameters.

AddStaticPickup(model, type, Float:x, Float:y, Float:z);

The type determines how long a pickup exists for, how long it stays hidden, what can pick it up etc, but there's only about 24 types so you don't have much option. YSI allows you to define exactly what can pick it up, how long it takes to respawn, how long it will exist for etc, so you have complete control (see the pickup documentation for more information).

Pickup_Add(model, Float:x, Float:y, Float:z, respawn, destroy, foot, vehicle);

The last four parameters are optional so if you just do a find and replace to convert AddStaticPickup to Pickup_Add and remove the type parameter you will get pickups which don't disappear on their own, can be picked up on foot but not in a vehicle and which take 1 minute to respawn.

Now you've converted those things you can copy them into OnGameModeInit in your YSI pawno and save.

The last thing to do before we can test is copy the random spawn code, this can't really be simplified by YSI much but it can be slightly improved using groups. At the top of your script add:

new
	gCopGroup;

Then in OnGameModeInit, above the add lines you just put in do:

gCopGroup = Group_CreateTemp()

We use Group_CreateTemp instead of Group_Create as it's only relevant for this game, it doesn't need saving. Then find your cop Class_Add lines:

Class_Add(265, 1958.3783, 1343.1572, 15.3746, 270.1425, 0, 0, 24, 300, -1, -1);
	Class_Add(266, 1958.3783, 1343.1572, 15.3746, 270.1425, 0, 0, 24, 300, -1, -1);
	Class_Add(267, 1958.3783, 1343.1572, 15.3746, 270.1425, 0, 0, 24, 300, -1, -1);
	Class_Add(268, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 24, 300, -1, -1);
	Class_Add(269, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 24, 300, -1, -1);
	Class_Add(270, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 24, 300, -1, -1);
	Class_Add(271, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 24, 300, -1, -1);
	Class_Add(272, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 24, 300, -1, -1);

And change them to Class_AddWithGroupSet(gCopGroup, ...:

Class_AddWithGroupSet(gCopGroup, 265, 1958.3783, 1343.1572, 15.3746, 270.1425, 0, 0, 24, 300, -1, -1);
	Class_AddWithGroupSet(gCopGroup, 266, 1958.3783, 1343.1572, 15.3746, 270.1425, 0, 0, 24, 300, -1, -1);
	Class_AddWithGroupSet(gCopGroup, 267, 1958.3783, 1343.1572, 15.3746, 270.1425, 0, 0, 24, 300, -1, -1);
	Class_AddWithGroupSet(gCopGroup, 268, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 24, 300, -1, -1);
	Class_AddWithGroupSet(gCopGroup, 269, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 24, 300, -1, -1);
	Class_AddWithGroupSet(gCopGroup, 270, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 24, 300, -1, -1);
	Class_AddWithGroupSet(gCopGroup, 271, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 24, 300, -1, -1);
	Class_AddWithGroupSet(gCopGroup, 272, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 24, 300, -1, -1);

This means that anyone who spawns as one of these classes will be added to the cop group automatically.

Now copy gRandomPlayerSpawns and gCopPlayerSpawns over and in OnPlayerSpawn do:

if (Group_HasPlayer(gCopGroup, playerid)) SetRandomPos(playerid, gCopPlayerSpawns);
else SetRandomPos(playerid, gRandomPlayerSpawns);

Finally, at the bottom of you code add the following functions:

SetRandomPos(playerid, Float:positions[][3], size = sizeof (positions))
{
	new
		rand = random(size);
	SetPlayerPos(playerid, positions[rand][0], positions[rand][1], positions[rand][2]);
}

If you wanted to add angles to that you would just need to add another float, if you wanted to add other data, such as interiors you would need to use some form of enum.

If you test now you will have most of LVDM done already, all the vehicles and spawns will be in place, it's just really the money side which is missing.