Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 4 additions & 73 deletions frontend/blog/2024-03-06-porting.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ public OnPlayerConnect(playerid)
}
```

## `ClearAnimations`

`ClearAnimations` is the dual of `ApplyAnimation` to stop a player performing the action previously requested. However, when used on a player in a vehicle this would also cause the player to be removed from the vehicle. This is a useful function, as it happens instantly, but is not within the purview of the `ClearAnimations` function. To force remove a player from a vehicle instantly use:

```c
RemovePlayerFromVehicle(playerid, true);
```

## Death money

When a player dies in San Andreas they get $100 deducted from them to cover hospital bills automatically. This feature remains in SA:MP, but is removed from open.mp to allow scripts to manage all their own money. Several scripts attempt to fix this already by adding $100 to a player after death, or on spawn. If this is your script simply delete the additional fix, although the code in open.mp does attempt to account for scripts that do this. If your script relied on this feature, simply add the following code to `OnPlayerDeath`:
Expand All @@ -113,67 +105,6 @@ When a player dies in San Andreas they get $100 deducted from them to cover hosp
GivePlayerMoney(playerid, -100);
```

## `OnPlayerConnect`

When a gamemode starts or restarts in SA:MP `OnPlayerConnect` is immediately called for all players already connected to the server, but it isn't when a filterscript starts or restarts. While the latter behaviour more closely matches the name, the former behaviour is extremely widely exploited in scripts, and so was extended to all script types in open.mp to maintain consistency.

Scripts which initialise data for a player no longer need to perform this code in two different locations:

```c
public OnFilterScriptInit()
{
for (new playerid = 0; playerid != MAX_PLAYERS; ++playerid)
{
if (IsPlayerConnected(playerid))
{
InitialisePlayer(playerid);
}
}
}

public OnPlayerConnect(playerid)
{
InitialisePlayer(playerid);
}
```

The loop in OnFilterScriptInit can now be removed:

```c
public OnPlayerConnect(playerid)
{
InitialisePlayer(playerid);
}
```

If a script exploited this fact to only run code for new players joining the server after the scripts starts, and not for those who were on before, this will no longer work, but is again easilly fixed:

```c
static bool:gAlreadyHere[MAX_PLAYERS];

public OnFilterScriptInit()
{
for (new playerid = 0; playerid != MAX_PLAYERS; ++playerid)
{
gAlreadyHere[playerid] = IsPlayerConnected(playerid);
}
}

public OnPlayerConnect(playerid)
{
if (gAlreadyHere[playerid])
{
gAlreadyHere[playerid] = false;
}
else
{
SendClientMessage(playerid, COLOUR_WARN, "You're late!");
}
}
```

This may look to simply trade one loop in `OnFilterScriptInit` off for another one, but wanting to exclude current players from some code is a less common use-case than wanting to do something for everyone, so this is overall a net improvement; and as stated before vastly less invasive than not calling `OnPlayerConnect` in gamemodes.

## Game texts

SA:MP has six different game text styles, but several of them are basically unusable. One fades in and out constantly, one disappears after a set time regardless of the time you put, and one never disappears regardless of the time selected. However it turns out that all of these game text styles can be accurately[^1] reproduced using text draws. Thus fixes.inc and subsequently open.mp did so. The appearance of the game texts is the same as before, the advantage being that all styles are usable, with the downside being that they no longer fade in and out.
Expand Down Expand Up @@ -217,14 +148,14 @@ Though since the highest value is a real player when there are people online thi

## Spellings

SA:MP is very inconsistent in its code spellings - some things use English, some things use American:
SA:MP is very inconsistent in its code spellings - some things use British English, some things use American:

- `Bumper` - English
- `Bumper` - British
- `Hood` - American
- `Armour` - English
- `Armour` - British
- `Stereo` - American

We have unified these, and settled on English spellings. So for example:
We have unified these, and settled on British spellings. So for example:

```c
TextDrawBoxColor(Text:textid, boxColor);
Expand Down