[Tutorial] Serverside Ammu-Nations!
#1

Serverside Ammu-Nations!
Foreword:
Have you ever noticed when your anticheat falsely detects if player buys weapons and armour in the ammu-nation either when buying player get back his money?
After this you probably immediately tried to disable all the default places or made huge checks in your anticheats, which would give the opportunity to cheat in these places.
Both of these options are not the best solution, so a couple of days ago I started to do it all from scratch on the server side.

This system retains all capabilities of Ammu-nation, but with this it makes cheating impossible (be it money, weapons or armor) in these places.

Attention! If you don't have an anti-money, weapons or armour hack, then cheating will be possible. This just saves your anticheat from unnecessary checks.

So, let's begin:

First, add defines for comfortable editing in future

Somewhere in the beginning:
PHP код:
#define COST_9MM        200
#define COST_SILENCED    600
#define COST_DEAGLE        1200
#define COST_TEC9        300
#define COST_MICRO_SMG    500
#define COST_SHOTGUN    600
#define COST_SAWNOFF    800
#define COST_COMBAT        1000
#define COST_ARMOR        200
#define COST_SMG        2000
#define COST_AK47        3500
#define COST_M4            4500 
The values on the right indicate the price in gaming $.
All prices are default, change it if you want.

Next we add an array with coordinates of Ammu-nations, so that you can easily find out where is the player.

Also add this somewhere in the beginning:
PHP код:
static const Float:AmmuCoords[][] =
{
    {
286.1489, -40.64431001.5156},
    {
286.8009, -82.54751001.5156},
    {
296.9199, -108.07191001.5156},
    {
314.8209, -141.4319999.6015},
    {
316.5249, -167.7069999.5937}
}; 
Ok now you need to add some variables which will keep IDs of created actors-sellers, menus and purchases weapons objects
(to be able to set the animation to the actors and add items to menus)

Again, paste to the variables (in beginning):
PHP код:
new
    
AmmuObjects[MAX_PLAYERS],
    
Menu:AmmuMenus[19],
    
AmmuActors[5]; 
Memory allocation is finished.
Add a couple of forward for public to be used.

To "forward"s (either at the beginning of script):
PHP код:
forward OnPlayerBuyInAmmuNation(playeridweaponidammocost);
forward DisableDefaultAmmu(playerid);
forward AmmuCheckPoint(playerid); 
Ok, now let's move to the creation of the actors and the menus.
In OnGameModeInit (or in OnFilterScriptInit, if you make the filterscript):
PHP код:
    AmmuActors[0] = CreateActor(179296.4576, -40.13241001.51560.0);
    
ApplyActorAnimation(AmmuActors[0], "FOOD""SHP_Tray_Pose"4.111100);
    
AmmuActors[1] = CreateActor(179295.6974, -82.51191001.51560.0);
    
ApplyActorAnimation(AmmuActors[1], "FOOD""SHP_Tray_Pose"4.111100);
    
AmmuActors[2] = CreateActor(179290.1882, -111.48141001.51560.0);
    
ApplyActorAnimation(AmmuActors[2], "FOOD""SHP_Tray_Pose"4.111100);
    
AmmuActors[3] = CreateActor(179308.1035, -143.0616999.60160.0);
    
ApplyActorAnimation(AmmuActors[3], "FOOD""SHP_Tray_Pose"4.111100);
    
AmmuActors[4] = CreateActor(179312.7362, -167.84999.59380.0);
    
ApplyActorAnimation(AmmuActors[4], "FOOD""SHP_Tray_Pose"4.111100);
    
AmmuMenus[0] = CreateMenu("Ammu-Nation"130.0150.0190.0180.0);
    
AddMenuItem(AmmuMenus[0], 0"Pistols");
    
AddMenuItem(AmmuMenus[0], 0"Micro SMGs");
    
AddMenuItem(AmmuMenus[0], 0"Shotguns");
    
AddMenuItem(AmmuMenus[0], 0"Armor");
    
AddMenuItem(AmmuMenus[0], 0"SMG");
    
AddMenuItem(AmmuMenus[0], 0"Assault");
    
AmmuMenus[1] = CreateMenu("Ammu-Nation"130.0150.0190.0180.0);
    
AddMenuItem(AmmuMenus[1], 0"9mm");
    
AddMenuItem(AmmuMenus[1], 0"Silenced 9mm");
    
AddMenuItem(AmmuMenus[1], 0"Desert Eagle");
    
AmmuMenus[2] = CreateMenu("Ammu-Nation"130.0150.0190.0180.0);
    
AddMenuItem(AmmuMenus[2], 0"Tec9");
    
AddMenuItem(AmmuMenus[2], 0"Micro SMG");
    
AmmuMenus[3] = CreateMenu("Ammu-Nation"130.0150.0190.0180.0);
    
AddMenuItem(AmmuMenus[3], 0"Shotgun");
    
AddMenuItem(AmmuMenus[3], 0"Sawnoff Shotgun");
    
AddMenuItem(AmmuMenus[3], 0"Combat Shotgun");
    
AmmuMenus[4] = CreateMenu("Ammu-Nation"130.0150.0190.0180.0);
    
AddMenuItem(AmmuMenus[4], 0"Body Armor");
    
AmmuMenus[5] = CreateMenu("Ammu-Nation"130.0150.0190.0180.0);
    
AddMenuItem(AmmuMenus[5], 0"SMG");
    
AmmuMenus[6] = CreateMenu("Ammu-Nation"130.0150.0190.0180.0);
    
AddMenuItem(AmmuMenus[6], 0"AK47");
    
AddMenuItem(AmmuMenus[6], 0"M4");
    
AmmuMenus[7] = CreateMenu("Ammu-Nation"230.0150.0100.0180.0);
    
SetMenuColumnHeader(AmmuMenus[7], 0"Weapon");
    
SetMenuColumnHeader(AmmuMenus[7], 1"Cost");
    
AddMenuItem(AmmuMenus[7], 0"9mm");
    
AddMenuItem(AmmuMenus[7], 1"$"#COST_9MM);
    
AmmuMenus[8] = CreateMenu("Ammu-Nation"230.0150.0100.0180.0);
    
SetMenuColumnHeader(AmmuMenus[8], 0"Weapon");
    
SetMenuColumnHeader(AmmuMenus[8], 1"Cost");
    
AddMenuItem(AmmuMenus[8], 0"Silenced 9mm");
    
AddMenuItem(AmmuMenus[8], 1"$"#COST_SILENCED);
    
AmmuMenus[9] = CreateMenu("Ammu-Nation"230.0150.0100.0180.0);
    
SetMenuColumnHeader(AmmuMenus[9], 0"Weapon");
    
SetMenuColumnHeader(AmmuMenus[9], 1"Cost");
    
AddMenuItem(AmmuMenus[9], 0"Desert Eagle");
    
AddMenuItem(AmmuMenus[9], 1"$"#COST_DEAGLE);
    
AmmuMenus[10] = CreateMenu("Ammu-Nation"230.0150.0100.0180.0);
    
SetMenuColumnHeader(AmmuMenus[10], 0"Weapon");
    
SetMenuColumnHeader(AmmuMenus[10], 1"Cost");
    
AddMenuItem(AmmuMenus[10], 0"Tec9");
    
AddMenuItem(AmmuMenus[10], 1"$"#COST_TEC9);
    
AmmuMenus[11] = CreateMenu("Ammu-Nation"230.0150.0100.0180.0);
    
SetMenuColumnHeader(AmmuMenus[11], 0"Weapon");
    
SetMenuColumnHeader(AmmuMenus[11], 1"Cost");
    
AddMenuItem(AmmuMenus[11], 0"Micro SMG");
    
AddMenuItem(AmmuMenus[11], 1"$"#COST_MICRO_SMG);
    
AmmuMenus[12] = CreateMenu("Ammu-Nation"230.0150.0100.0180.0);
    
SetMenuColumnHeader(AmmuMenus[12], 0"Weapon");
    
SetMenuColumnHeader(AmmuMenus[12], 1"Cost");
    
AddMenuItem(AmmuMenus[12], 0"Shotgun");
    
AddMenuItem(AmmuMenus[12], 1"$"#COST_SHOTGUN);
    
AmmuMenus[13] = CreateMenu("Ammu-Nation"230.0150.0100.0180.0);
    
SetMenuColumnHeader(AmmuMenus[13], 0"Weapon");
    
SetMenuColumnHeader(AmmuMenus[13], 1"Cost");
    
AddMenuItem(AmmuMenus[13], 0"Sawnoff Shotgun");
    
AddMenuItem(AmmuMenus[13], 1"$"#COST_SAWNOFF);
    
AmmuMenus[14] = CreateMenu("Ammu-Nation"230.0150.0100.0180.0);
    
SetMenuColumnHeader(AmmuMenus[14], 0"Weapon");
    
SetMenuColumnHeader(AmmuMenus[14], 1"Cost");
    
AddMenuItem(AmmuMenus[14], 0"Combat Shotgun");
    
AddMenuItem(AmmuMenus[14], 1"$"#COST_COMBAT);
    
AmmuMenus[15] = CreateMenu("Ammu-Nation"230.0150.0100.0180.0);
    
SetMenuColumnHeader(AmmuMenus[15], 0"Weapon");
    
SetMenuColumnHeader(AmmuMenus[15], 1"Cost");
    
AddMenuItem(AmmuMenus[15], 0"Body Armor");
    
AddMenuItem(AmmuMenus[15], 1"$"#COST_ARMOR);
    
AmmuMenus[16] = CreateMenu("Ammu-Nation"230.0150.0100.0180.0);
    
SetMenuColumnHeader(AmmuMenus[16], 0"Weapon");
    
SetMenuColumnHeader(AmmuMenus[16], 1"Cost");
    
AddMenuItem(AmmuMenus[16], 0"SMG");
    
AddMenuItem(AmmuMenus[16], 1"$"#COST_SMG);
    
AmmuMenus[17] = CreateMenu("Ammu-Nation"230.0150.0100.0180.0);
    
SetMenuColumnHeader(AmmuMenus[17], 0"Weapon");
    
SetMenuColumnHeader(AmmuMenus[17], 1"Cost");
    
AddMenuItem(AmmuMenus[17], 0"AK47");
    
AddMenuItem(AmmuMenus[17], 1"$"#COST_AK47);
    
AmmuMenus[18] = CreateMenu("Ammu-Nation"230.0150.0100.0180.0);
    
SetMenuColumnHeader(AmmuMenus[18], 0"Weapon");
    
SetMenuColumnHeader(AmmuMenus[18], 1"Cost");
    
AddMenuItem(AmmuMenus[18], 0"M4");
    
AddMenuItem(AmmuMenus[18], 1"$"#COST_M4); 
Now in each Ammu-Nation we have added the sellers and created all the necessary menu for buy weapons.

Now we go to OnGameModeExit (or OnFilterScriptExit) and insert following:
PHP код:
    new i;
    for(
sizeof(AmmuActors) - 1!= -1; --iDestroyActor(AmmuActors[i]);
    for(
sizeof(AmmuMenus) - 1!= -1; --iDestroyMenu(AmmuMenus[i]); 
The sense of the code: destroy all created actors and the menus when the server/filterscript shuts down.

So, now we need to remove the object (which we will create below) when player exit, if he suddenly decides to quit during the purchase of weapons.
In OnPlayerDisconnect:
PHP код:
    DestroyPlayerObject(playeridAmmuObjects[playerid]);
    
AmmuObjects[playerid] = 0
Now in OnPlayerInteriorChange:
PHP код:
    switch(newinteriorid)
    {
        case 
1467SetTimerEx("DisableDefaultAmmu"10000"i"playerid);
        default: 
DisablePlayerCheckpoint(playerid);
    } 
At the entrance to the interiors of Ammu-Nations will be called a timer, in which we disable default ammu-nations.
I use the timer because after changing the interior player still doesn't move to it.
Otherwise we hide checkpoint (which also will created below) for player, if for example he left this interior and went to another.

In OnPlayerEnterCheckpoint add the following:
PHP код:
    if(IsPlayerInRangeOfPoint(playerid5.0296.3255, -38.30401001.5156))
    {
        
DisablePlayerCheckpoint(playerid);
        
TogglePlayerControllable(playerid0);
        
SetPlayerFacingAngle(playerid180.0);
        
ShowMenuForPlayer(AmmuMenus[0], playerid);
        
SetPlayerCameraPos(playerid296.55, -38.41002.2);
        
SetPlayerCameraLookAt(playerid296.4576, -40.13241001.7156);
        
SetTimerEx("AmmuCheckPoint"10000"i"playerid);
    }
    else if(
IsPlayerInRangeOfPoint(playerid5.0295.7595, -80.55791001.5156))
    {
        
DisablePlayerCheckpoint(playerid);
        
TogglePlayerControllable(playerid0);
        
SetPlayerFacingAngle(playerid180.0);
        
ShowMenuForPlayer(AmmuMenus[0], playerid);
        
SetPlayerCameraPos(playerid295.7895, -80.551002.2);
        
SetPlayerCameraLookAt(playerid295.6974, -82.51191001.5156);
        
SetTimerEx("AmmuCheckPoint"10000"i"playerid);
    }
    else if(
IsPlayerInRangeOfPoint(playerid5.0290.1898, -109.4821001.5156))
    {
        
DisablePlayerCheckpoint(playerid);
        
TogglePlayerControllable(playerid0);
        
SetPlayerFacingAngle(playerid180.0);
        
ShowMenuForPlayer(AmmuMenus[0], playerid);
        
SetPlayerCameraPos(playerid290.2898, -109.4821002.2);
        
SetPlayerCameraLookAt(playerid290.1882, -111.48141001.5156);
        
SetTimerEx("AmmuCheckPoint"10000"i"playerid);
    }
    else if(
IsPlayerInRangeOfPoint(playerid5.0308.2072, -141.0583999.6016))
    {
        
DisablePlayerCheckpoint(playerid);
        
TogglePlayerControllable(playerid0);
        
SetPlayerFacingAngle(playerid180.0);
        
ShowMenuForPlayer(AmmuMenus[0], playerid);
        
SetPlayerCameraPos(playerid308.2072, -141.05831000.3016);
        
SetPlayerCameraLookAt(playerid308.1035, -143.0616999.6016);
        
SetTimerEx("AmmuCheckPoint"10000"i"playerid);
    }
    else if(
IsPlayerInRangeOfPoint(playerid5.0312.6785, -165.5487999.601))
    {
        
DisablePlayerCheckpoint(playerid);
        
TogglePlayerControllable(playerid0);
        
SetPlayerFacingAngle(playerid180.0);
        
ShowMenuForPlayer(AmmuMenus[0], playerid);
        
SetPlayerCameraPos(playerid312.8785, -165.84871000.301);
        
SetPlayerCameraLookAt(playerid312.7362, -167.84999.5938);
        
SetTimerEx("AmmuCheckPoint"10000"i"playerid);
    } 
When the player enters the checkpoint, he will see buy menu.

Now go to in OnPlayerSelectedMenuRow, which contains main code.
In OnPlayerSelectedMenuRow:
PHP код:
    new Menu:menu GetPlayerMenu(playerid);
    if(
menu == AmmuMenus[0])
    {
        if(-
row 6ShowMenuForPlayer(AmmuMenus[row 1], playerid);
    }
    else if(
menu == AmmuMenus[1])
    {
        if(-
row 3)
        {
            new 
weaponammo;
            
GetPlayerWeaponData(playerid2weaponammo);
            if(
weapon && weapon != row 22AmmuSlotReplace(playerid);
            if(
IsPlayerInRangeOfPoint(playerid5.0296.3255, -38.30401001.5156))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 346296.6729, -39.56671001.5991270.00.0155.0);
            else if(
IsPlayerInRangeOfPoint(playerid5.0295.7595, -80.55791001.5156))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 346295.9295, -81.75791001.5991270.00.0155.0);
            else if(
IsPlayerInRangeOfPoint(playerid5.0290.1898, -109.4821001.5156))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 346290.3998, -110.7821001.5991270.00.0155.0);
            else if(
IsPlayerInRangeOfPoint(playerid5.0308.2072, -141.0583999.6016))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 346308.3452, -142.3583999.6851270.00.0155.0);
            else if(
IsPlayerInRangeOfPoint(playerid5.0312.6785, -165.5487999.601))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 346312.9585, -167.1187999.6845270.00.0155.0);
            
ShowMenuForPlayer(AmmuMenus[row 7], playerid);
        }
    }
    else if(
menu == AmmuMenus[2])
    {
        if(-
row 2)
        {
            new 
weaponammo;
            
GetPlayerWeaponData(playerid4weaponammo);
            if(
weapon && (!row && weapon != 32 || row && weapon != 28)) AmmuSlotReplace(playerid);
            if(
IsPlayerInRangeOfPoint(playerid5.0296.3255, -38.30401001.5156))
            {
                if(!
rowAmmuObjects[playerid] = CreatePlayerObject(playerid372296.7229, -39.56671001.5991270.03.0155.0);
                else 
AmmuObjects[playerid] = CreatePlayerObject(playerid352296.6529, -39.56671001.5991265.03.0155.0);
            }
            else if(
IsPlayerInRangeOfPoint(playerid5.0295.7595, -80.55791001.5156))
            {
                if(!
rowAmmuObjects[playerid] = CreatePlayerObject(playerid372295.9595, -81.75791001.5991270.03.0155.0);
                else 
AmmuObjects[playerid] = CreatePlayerObject(playerid352295.8895, -81.75791001.5991265.03.0155.0);
            }
            else if(
IsPlayerInRangeOfPoint(playerid5.0290.1898, -109.4821001.5156))
            {
                if(!
rowAmmuObjects[playerid] = CreatePlayerObject(playerid372290.4598, -110.7821001.5991270.03.0155.0);
                else 
AmmuObjects[playerid] = CreatePlayerObject(playerid352290.3898, -110.7821001.5991265.03.0155.0);
            }
            else if(
IsPlayerInRangeOfPoint(playerid5.0308.2072, -141.0583999.6016))
            {
                if(!
rowAmmuObjects[playerid] = CreatePlayerObject(playerid372308.3852, -142.3583999.6851270.03.0155.0);
                else 
AmmuObjects[playerid] = CreatePlayerObject(playerid352308.3152, -142.3583999.6851265.03.0155.0);
            }
            else if(
IsPlayerInRangeOfPoint(playerid5.0312.6785, -165.5487999.601))
            {
                if(!
rowAmmuObjects[playerid] = CreatePlayerObject(playerid372313.0085, -167.1187999.6845270.03.0155.0);
                else 
AmmuObjects[playerid] = CreatePlayerObject(playerid352312.9185, -167.1187999.6845265.03.0155.0);
            }
            
ShowMenuForPlayer(AmmuMenus[row 10], playerid);
        }
    }
    else if(
menu == AmmuMenus[3])
    {
        if(-
row 3)
        {
            new 
weaponammo;
            
GetPlayerWeaponData(playerid3weaponammo);
            if(
weapon && weapon != row 25AmmuSlotReplace(playerid);
            if(
IsPlayerInRangeOfPoint(playerid5.0296.3255, -38.30401001.5156))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 349296.7829, -39.56671001.5991265.010.0155.0);
            else if(
IsPlayerInRangeOfPoint(playerid5.0295.7595, -80.55791001.5156))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 349296.0295, -81.78791001.5991265.010.0155.0);
            else if(
IsPlayerInRangeOfPoint(playerid5.0290.1898, -109.4821001.5156))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 349290.4898, -110.7821001.5991265.010.0155.0);
            else if(
IsPlayerInRangeOfPoint(playerid5.0308.2072, -141.0583999.6016))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 349308.4182, -142.3583999.6851265.010.0155.0);
            else if(
IsPlayerInRangeOfPoint(playerid5.0312.6785, -165.5487999.601))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 349313.0585, -167.1187999.6845265.010.0155.0);
            
ShowMenuForPlayer(AmmuMenus[row 12], playerid);
        }
    }
    else if(
menu == AmmuMenus[4])
    {
        if(
IsPlayerInRangeOfPoint(playerid5.0296.3255, -38.30401001.5156))
            
AmmuObjects[playerid] = CreatePlayerObject(playerid373296.6629, -39.56671002.0332.0295.085.0);
        else if(
IsPlayerInRangeOfPoint(playerid5.0295.7595, -80.55791001.5156))
            
AmmuObjects[playerid] = CreatePlayerObject(playerid373295.9095, -81.75791002.0332.0295.085.0);
        else if(
IsPlayerInRangeOfPoint(playerid5.0290.1898, -109.4821001.5156))
            
AmmuObjects[playerid] = CreatePlayerObject(playerid373290.3998, -110.7821002.0332.0295.085.0);
        else if(
IsPlayerInRangeOfPoint(playerid5.0308.2072, -141.0583999.6016))
            
AmmuObjects[playerid] = CreatePlayerObject(playerid373308.3182, -142.35831000.1051332.0295.085.0);
        else if(
IsPlayerInRangeOfPoint(playerid5.0312.6785, -165.5487999.601))
            
AmmuObjects[playerid] = CreatePlayerObject(playerid373312.9685, -167.11871000.1045332.0295.085.0);
        
ShowMenuForPlayer(AmmuMenus[15], playerid);
    }
    else if(
menu == AmmuMenus[5])
    {
        new 
weaponammo;
        
GetPlayerWeaponData(playerid4weaponammo);
        if(
weapon && weapon != 29AmmuSlotReplace(playerid);
        if(
IsPlayerInRangeOfPoint(playerid5.0296.3255, -38.30401001.5156))
            
AmmuObjects[playerid] = CreatePlayerObject(playerid353296.6829, -39.48671001.5991265.08.0155.0);
        else if(
IsPlayerInRangeOfPoint(playerid5.0295.7595, -80.55791001.5156))
            
AmmuObjects[playerid] = CreatePlayerObject(playerid353295.9595, -81.75791001.5991265.08.0155.0);
        else if(
IsPlayerInRangeOfPoint(playerid5.0290.1898, -109.4821001.5156))
            
AmmuObjects[playerid] = CreatePlayerObject(playerid353290.4198, -110.7821001.5991265.08.0155.0);
        else if(
IsPlayerInRangeOfPoint(playerid5.0308.2072, -141.0583999.6016))
            
AmmuObjects[playerid] = CreatePlayerObject(playerid353308.3382, -142.3583999.6851265.08.0155.0);
        else if(
IsPlayerInRangeOfPoint(playerid5.0312.6785, -165.5487999.601))
            
AmmuObjects[playerid] = CreatePlayerObject(playerid353312.9785, -167.1187999.6845265.08.0155.0);
        
ShowMenuForPlayer(AmmuMenus[16], playerid);
    }
    else if(
menu == AmmuMenus[6])
    {
        if(-
row 2)
        {
            new 
weaponammo;
            
GetPlayerWeaponData(playerid5weaponammo);
            if(
weapon && weapon != row 30AmmuSlotReplace(playerid);
            if(
IsPlayerInRangeOfPoint(playerid5.0296.3255, -38.30401001.5156))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 355296.7529, -39.56671001.5991265.03.0155.0);
            else if(
IsPlayerInRangeOfPoint(playerid5.0295.7595, -80.55791001.5156))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 355295.9595, -81.75791001.5991265.03.0155.0);
            else if(
IsPlayerInRangeOfPoint(playerid5.0290.1898, -109.4821001.5156))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 355290.4198, -110.7821001.5991265.03.0155.0);
            else if(
IsPlayerInRangeOfPoint(playerid5.0308.2072, -141.0583999.6016))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 355308.3582, -142.3583999.6851265.03.0155.0);
            else if(
IsPlayerInRangeOfPoint(playerid5.0312.6785, -165.5487999.601))
                
AmmuObjects[playerid] = CreatePlayerObject(playeridrow 355312.9985, -167.1187999.6845265.03.0155.0);
            
ShowMenuForPlayer(AmmuMenus[row 17], playerid);
        }
    }
    else if(
menu == AmmuMenus[7])
    {
        if(
GetPlayerMoney(playerid) < COST_9MMAmmuBuyDenied(playerid);
        else 
OnPlayerBuyInAmmuNation(playerid2230COST_9MM);
        
ShowMenuForPlayer(AmmuMenus[7], playerid);
    }
    else if(
menu == AmmuMenus[8])
    {
        if(
GetPlayerMoney(playerid) < COST_SILENCEDAmmuBuyDenied(playerid);
        else 
OnPlayerBuyInAmmuNation(playerid2330COST_SILENCED);
        
ShowMenuForPlayer(AmmuMenus[8], playerid);
    }
    else if(
menu == AmmuMenus[9])
    {
        if(
GetPlayerMoney(playerid) < COST_DEAGLEAmmuBuyDenied(playerid);
        else 
OnPlayerBuyInAmmuNation(playerid2410COST_DEAGLE);
        
ShowMenuForPlayer(AmmuMenus[9], playerid);
    }
    else if(
menu == AmmuMenus[10])
    {
        if(
GetPlayerMoney(playerid) < COST_TEC9AmmuBuyDenied(playerid);
        else 
OnPlayerBuyInAmmuNation(playerid3260COST_TEC9);
        
ShowMenuForPlayer(AmmuMenus[10], playerid);
    }
    else if(
menu == AmmuMenus[11])
    {
        if(
GetPlayerMoney(playerid) < COST_MICRO_SMGAmmuBuyDenied(playerid);
        else 
OnPlayerBuyInAmmuNation(playerid2860COST_MICRO_SMG);
        
ShowMenuForPlayer(AmmuMenus[11], playerid);
    }
    else if(
menu == AmmuMenus[12])
    {
        if(
GetPlayerMoney(playerid) < COST_SHOTGUNAmmuBuyDenied(playerid);
        else 
OnPlayerBuyInAmmuNation(playerid2515COST_SHOTGUN);
        
ShowMenuForPlayer(AmmuMenus[12], playerid);
    }
    else if(
menu == AmmuMenus[13])
    {
        if(
GetPlayerMoney(playerid) < COST_SAWNOFFAmmuBuyDenied(playerid);
        else 
OnPlayerBuyInAmmuNation(playerid2612COST_SAWNOFF);
        
ShowMenuForPlayer(AmmuMenus[13], playerid);
    }
    else if(
menu == AmmuMenus[14])
    {
        if(
GetPlayerMoney(playerid) < COST_COMBATAmmuBuyDenied(playerid);
        else 
OnPlayerBuyInAmmuNation(playerid2710COST_COMBAT);
        
ShowMenuForPlayer(AmmuMenus[14], playerid);
    }
    else if(
menu == AmmuMenus[15])
    {
        if(
GetPlayerMoney(playerid) < COST_ARMORAmmuBuyDenied(playerid);
        else
        {
            new 
Float:armour;
            
GetPlayerArmour(playeridarmour);
            if(
armour >= 100.0)
            {
                
PlayerPlaySound(playerid10530.00.00.0);
                
GameTextForPlayer(playerid"~n~~n~~n~~n~~n~~n~~n~~n~~w~You cannot buy any more armor."50003);
            }
            else 
OnPlayerBuyInAmmuNation(playerid0100COST_ARMOR);
        }
        
ShowMenuForPlayer(AmmuMenus[15], playerid);
    }
    else if(
menu == AmmuMenus[16])
    {
        if(
GetPlayerMoney(playerid) < COST_SMGAmmuBuyDenied(playerid);
        else 
OnPlayerBuyInAmmuNation(playerid2990COST_SMG);
        
ShowMenuForPlayer(AmmuMenus[16], playerid);
    }
    else if(
menu == AmmuMenus[17])
    {
        if(
GetPlayerMoney(playerid) < COST_AK47AmmuBuyDenied(playerid);
        else 
OnPlayerBuyInAmmuNation(playerid30120COST_AK47);
        
ShowMenuForPlayer(AmmuMenus[17], playerid);
    }
    else if(
menu == AmmuMenus[18])
    {
        if(
GetPlayerMoney(playerid) < COST_M4AmmuBuyDenied(playerid);
        else 
OnPlayerBuyInAmmuNation(playerid3190COST_M4);
        
ShowMenuForPlayer(AmmuMenus[18], playerid);
    } 
If you use a custom function for get the money of the player (not GetPlayerMoney), you need to find in the above code all these functions and replace it on your function.

The hardest part behind)
Here we check what dialog has chosen by player and depending on the choice we give him weapon, showing the same weapon object on the counter. Ibid at confirmation of purchase we called public OnPlayerBuyInAmmuNation, which we add later.

But first you need to make exit of our menu.
Therefore, insert in OnPlayerExitedMenu:
PHP код:
    new Menu:menu GetPlayerMenu(playerid);
    if(
menu == AmmuMenus[17] || menu == AmmuMenus[18])
    {
        
DestroyPlayerObject(playeridAmmuObjects[playerid]);
        
ShowMenuForPlayer(AmmuMenus[6], playerid);
    }
    else if(
menu == AmmuMenus[16])
    {
        
DestroyPlayerObject(playeridAmmuObjects[playerid]);
        
ShowMenuForPlayer(AmmuMenus[5], playerid);
    }
    else if(
menu == AmmuMenus[15])
    {
        
DestroyPlayerObject(playeridAmmuObjects[playerid]);
        
ShowMenuForPlayer(AmmuMenus[4], playerid);
    }
    else if(
menu == AmmuMenus[12] || menu == AmmuMenus[13] || menu == AmmuMenus[14])
    {
        
DestroyPlayerObject(playeridAmmuObjects[playerid]);
        
ShowMenuForPlayer(AmmuMenus[3], playerid);
    }
    else if(
menu == AmmuMenus[10] || menu == AmmuMenus[11])
    {
        
DestroyPlayerObject(playeridAmmuObjects[playerid]);
        
ShowMenuForPlayer(AmmuMenus[2], playerid);
    }
    else if(
menu == AmmuMenus[7] || menu == AmmuMenus[8] || menu == AmmuMenus[9])
    {
        
DestroyPlayerObject(playeridAmmuObjects[playerid]);
        
ShowMenuForPlayer(AmmuMenus[1], playerid);
    }
    else if(
menu == AmmuMenus[1] || menu == AmmuMenus[2] || menu == AmmuMenus[3]
    || 
menu == AmmuMenus[4] || menu == AmmuMenus[5] || menu == AmmuMenus[6]) ShowMenuForPlayer(AmmuMenus[0], playerid);
    else if(
menu == AmmuMenus[0])
    {
        
TogglePlayerControllable(playerid1);
        
SetCameraBehindPlayer(playerid);
    } 
We have made exit of the menus, where at the exit from the last menu we go back to the back menu until they don't close and player will not return to the old position.

Things are easy: add our created publics and functions.
Somewhere (maybe at the end of your script):
PHP код:
public DisableDefaultAmmu(playerid)
{
    if(
IsPlayerConnected(playerid))
    {
        new 
Float:pXFloat:pYFloat:pZ;
        
GetPlayerPos(playeridpXpYpZ);
        if(
pZ 800.0)
        {
            
SetPlayerShopName(playerid"");
            
AmmuCheckPoint(playerid);
        }
        else 
SetTimerEx("DisableDefaultAmmu"10000"i"playerid);
    }
    return 
1;

This is called by the timer, remember? Disables default ammu-nation.

Then, somewhere at the end too:
PHP код:
public AmmuCheckPoint(playerid)
{
    new 
interior GetPlayerInterior(playerid);
    if(
interior == && IsPlayerInRangeOfPoint(playerid30.0AmmuCoords[0][0], AmmuCoords[0][1], AmmuCoords[0][2]))
    {
        if(
IsPlayerInRangeOfPoint(playerid1.2296.3255, -38.30401001.5156))
            
SetTimerEx("AmmuCheckPoint"10000"i"playerid);
        else 
SetPlayerCheckpoint(playerid296.3255, -38.30401001.51561.0);
    }
    else if(
interior == && IsPlayerInRangeOfPoint(playerid30.0AmmuCoords[1][0], AmmuCoords[1][1], AmmuCoords[1][2]))
    {
        if(
IsPlayerInRangeOfPoint(playerid1.2295.7595, -80.55791001.5156))
            
SetTimerEx("AmmuCheckPoint"10000"i"playerid);
        else 
SetPlayerCheckpoint(playerid295.7595, -80.55791001.51561.0);
    }
    else if(
interior == && IsPlayerInRangeOfPoint(playerid30.0AmmuCoords[2][0], AmmuCoords[2][1], AmmuCoords[2][2]))
    {
        if(
IsPlayerInRangeOfPoint(playerid1.2290.1898, -109.4821001.5156))
            
SetTimerEx("AmmuCheckPoint"10000"i"playerid);
        else 
SetPlayerCheckpoint(playerid290.1898, -109.4821001.51561.0);
    }
    else if(
interior == && IsPlayerInRangeOfPoint(playerid30.0AmmuCoords[3][0], AmmuCoords[3][1], AmmuCoords[3][2]))
    {
        if(
IsPlayerInRangeOfPoint(playerid1.2308.2072, -141.0583999.6016))
            
SetTimerEx("AmmuCheckPoint"10000"i"playerid);
        else 
SetPlayerCheckpoint(playerid308.2072, -141.0583999.60161.0);
    }
    else if(
interior == && IsPlayerInRangeOfPoint(playerid30.0AmmuCoords[4][0], AmmuCoords[4][1], AmmuCoords[4][2]))
    {
        if(
IsPlayerInRangeOfPoint(playerid1.2312.6785, -165.5487999.601))
            
SetTimerEx("AmmuCheckPoint"10000"i"playerid);
        else 
SetPlayerCheckpoint(playerid312.6785, -165.5487999.6011.0);
    }
    return 
1;

This shows our checkpoint, when player enters the ammu-nation. The above code checks in which ammu-nation the player is and if player is already at the checkpoint, we run the timer again as long as he doesn't move from it. Otherwise, we create a checkpoint (but only if player in the Ammu-Nation).

Finally, create OnPlayerBuyInAmmuNation, which is called when player has bought weapons/armor.
PHP код:
public OnPlayerBuyInAmmuNation(playeridweaponidammocost)
{
    new const 
fmt_str[] = "Weapon purchased at the price of $%d"//Here your text
    
new str[sizeof(fmt_str) + 3];
    
GivePlayerMoney(playerid, -cost); //If there is an anti-money hack, then replace this function
    
GivePlayerWeapon(playeridweaponidammo); //If there is an anti-weapon hack, too, replace if necessary
    
if(!weaponidSetPlayerArmour(playeridammo); //And here too, just with the armour
    
format(strsizeof strfmt_strcost);
    
SendClientMessage(playerid, -1str);
    return 
1;

Yay, almost everything already created!
Only a little things (they too at the end):
PHP код:
AmmuBuyDenied(playerid)
{
    
PlayerPlaySound(playerid10530.00.00.0);
    
GameTextForPlayer(playerid"~n~~n~~n~~n~~n~~n~~n~~n~~w~You don't have enough money to buy this item."50003);
    return 
1;
}
AmmuSlotReplace(playerid)
{
    
GameTextForPlayer(playerid"~n~~n~~n~~n~~n~~n~~n~~n~~w~Buying this item will replace the weapon in this slot."50003);
    return 
1;

The first function is called when player doesn't have enough money to buy some weapon. In this case we send to player the corresponding text (can be replaced).
The second function is called when player wants to buy a weapon, but he already has a counterpart. Script will send message to player that his weapon will be replaced by a purchased weapon.
Again, change the text if you need.

And because this is only the foundation, you can modify this script to your liking: by adding, for example, the choice of weapons with the smooth movement of the camera or something else.

Thanks:
Carlton - coordinates of ammu-nations

Good luck.
Reply
#2

Tutorial? You literally just gave all of the code to do it. Why not just release an include?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)