[FilterScript] Modshop Fix - No collisions & passengers can enter
#1

pawn Код:
#include <a_samp>

new playerPrevWorld[MAX_PLAYERS],
    maxPlayers;

public OnFilterScriptInit()
    maxPlayers = GetMaxPlayers();

public OnEnterExitModShop(playerid, enterexit, interiorid)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(vehicleid)
    {
        if(enterexit) // Enter
        {
            playerPrevWorld[playerid] = GetPlayerVirtualWorld(playerid);
            SetVehicleVirtualWorld(vehicleid, playerid);
            for(new veh_playerid = 0; veh_playerid < maxPlayers; veh_playerid ++)
            {
                if(IsPlayerConnected(veh_playerid) && GetPlayerVehicleID(veh_playerid) == vehicleid)
                    SetPlayerVirtualWorld(veh_playerid, playerid);
            }
        }
        else // Exit
        {
            SetVehicleVirtualWorld(vehicleid, playerPrevWorld[playerid]);
            for(new veh_playerid = 0; veh_playerid < maxPlayers; veh_playerid ++)
            {
                if(IsPlayerConnected(veh_playerid) && GetPlayerVehicleID(veh_playerid) == vehicleid)
                    SetPlayerVirtualWorld(veh_playerid, playerPrevWorld[playerid]);
            }
        }
    }
}
Enjoy.
Reply
#2

#if defined MAX_PLAYERS
#undef MAX_PLAYERS
#endif
#define MAX_PLAYERS 32

or
#undef MAX_PLAYERS
const MAX_PLAYERS = 32;
Reply
#3

Your code is pretty struggling to read I must say, all that world naming is weird.

I'm not into competition but I would do it like this.

pawn Код:
public OnEnterExitModShop(playerid, enterexit, interiorid)
{
    new vehicleid = GetPlayerVehicleID(playerid), maxPassengers, passengerCount;
   
    maxPassengers = GetVehicleMaxPassengers(GetVehicleModel(vehicleid)) + 1; // counting driver
   
    if(enterexit) {
        SetVehicleVirtualWorld(vehicleid, playerid);
        foreach(Player, i)
        {
            if(GetPlayerVehicleID(i) == vehicleid) {
                SetPlayerVirtualWorld(i, playerid);
                if(++passengerCount == maxPassengers)
                    break;
            }
        }
    }
    else {
        //SetVehicleHealth(vehicleid, MAX_VHEALTH);
        //safeGivePlayerMoney(playerid, -100);
        SetVehicleVirtualWorld(vehicleid, 0);
        foreach(Player, i)
        {
            if(GetPlayerVehicleID(i) == vehicleid) {
                SetPlayerVirtualWorld(i, 0);
                if(++passengerCount == maxPassengers)
                    break;
            }
        }
    }
    return 1;
}
GetVehicleMaxPassengers
Reply
#4

Edited the first post.
Reply
#5

Now thats better, I don't know where all that inefficient code was coming from.

but there's one thing my code has over yours, a limit. It stops when it found the maximum number of possible people in a vehicle, check that out.

why put
pawn Код:
#if defined MAX_PLAYERS
#undef MAX_PLAYERS
#endif
#define MAX_PLAYERS 32
in your code, I'm sure this is not newbie friendly.
Reply
#6

Quote:
Originally Posted by Kar
Посмотреть сообщение
why put
pawn Код:
#if defined MAX_PLAYERS
#undef MAX_PLAYERS
#endif
#define MAX_PLAYERS 32
in your code, I'm sure this is not newbie friendly.
I'm sure you know why i put it there but you're probably right. Removed it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)