How to make Airdrop system? (using Mapandreas) -
Gammix - 08.06.2015
How to make Airdrop system
This tutorial will explain you how you can simply make an airdrop system using MapAndreas version 1.2 by Mauzen and Kalcor.
We will use object id
18849 as our falling airdrop object.
Video demonstration - Click
[ame]http://www.youtube.com/watch?v=4S5AXk3ZWnk[/ame]
(Sorry for the quality)
Before starting our script, we must include map andreas include. So add this with your includes section in your script:
The plugin can be downloaded from here:
https://sampforum.blast.hk/showthread.php?tid=275492
Now lets start scripting; First of all, we need to declare a macro defining maximum airdrops we can create, or we can drop.
MAX_AIRDROPS here is the maximum airdrops we can create at one time or throw at one time. I think 100 is enough for a server with 150 - 200 players. Adjust accordingly.
Now adding arrays for airdrops, storing data and managing our airdrops.
pawn Код:
enum AirdropEnum
{
//the object which will be created and moved
a_object,
//expire time after which the airdrop will be destroyed automatically
a_expire_timer,
//position where the airdrop will fall
Float:a_pos[3],
//just to check if the airdrop exists
bool:a_exist,
//this is used just in case no one picks up the airdrop while its in air
bool:a_droped
};
new gAirdrop[MAX_AIRDROPS][AirdropEnum];
We need an additional variable/player array to use as a timer. The timer is for detecting if the player is near an airdrop, and so we can display our message.
pawn Код:
new gAirdropTimer[MAX_PLAYERS];
NOTE: If you have already a timer for player which is repeating, then ignore this.
You may change the names if they collapse or cause trouble!
Starting, initiating
Just before making our functions, we need to set default values of array while initiating your script.
If you use in Gamemode, we will use OnGameModeInit or else use OnFilterScriptInit.
Suppose its a gamemode, we will set all airdrops as non existing, i.e. false.
pawn Код:
public OnGameModeInit()
{
//looping through all airdrops
for(new i; i < MAX_AIRDROPS; i++)
{
//this means, the airdrop is non existing
gAirdrop[i][AIRDROP_EXIST] = false;
}
return 1;
}
Also for initiating our MapAndreas, we have to use this:
pawn Код:
public OnGameModeInit()
{
//initiating mapandreas plugin
MapAndreas_Init(MAP_ANDREAS_MODE_FULL);
}
We also have a timer for player so we will create one timer in OnPlayerConnect.
pawn Код:
public OnPlayerConnect(playerid)
{
//create a timer with interval of 1000 ms i.e. 1 second.
gAirdropTimer[playerid] = SetTimerEx("OnPlayerTimeUpdate", 1000, true, "i", playerid);
//the timer is repearing because we will need this every time to check the player!
//you can also have a custom interval. But i recommend 1 second
return 1;
}
You can also have a custom interval. But i recommend
1 second.
Creating Airdrops
We will declare a function so its easy for me and you to create airdrops in just one line.
We will use map andreas to get our Z coordinate so the airdrop drops on the ground accurately.
pawn Код:
new Float:z;
MapAndreas_FindZ_For2DCoord(x, y, z);
The x & y are the coordinates where the pickup will be droped, 2D requirement only.
The actual function. You may declare this individually in your script anywhere.
pawn Код:
/*
PARAMS:
x - x cordinate
y - y cordinate
* speed - speed at which the airdrop will fall from the sky
* height - the height from which the airdrop will be dropped
NOTE:
- the expiretime is for a timer which will start when the airdrop is droped on the ground
- the params with * are non mandatory, they have a default value
*/
CreateAirdrop(Float:x, Float:y, Float:speed = 5.0, Float:height = 100.0)
{
//looping through all airdrops
for(new i; i < MAX_AIRDROPS; i++)
{
//this check is for checking if the airdrop is existing or not
if(! gAirdrop[i][a_exist])
{
//we have found an empty slot
//using mapandreas, we get the Z angle
new Float:z;
MapAndreas_FindZ_For2DCoord(x, y, z);
//we have just obtained our Z cordinate
//but the object will be placed from center and that will look like half in ground and half on ground
//So we add an additional value into Z for betterment :)
z += 7.5;
//now create the airdrop object, the X & Y cordinates are from params and the Z is from map andreas + our value
//For throwing the airdrop from an height, we will add 'height' param value to Z
gAirdrop[i][a_object] = CreateObject(18849, x, y, (z + height), 0.0, 0.0, 0.0);
//once the object is created in the air, we make it move towards the ground
//Here only the Z cordinate plays the role, we will move the object to the initial Z cordinate
//the 'speed' is from params
MoveObject(gAirdrop[i][a_object], x, y, z, speed);
//for storing the position where the object will be droped, we use our array
gAirdrop[i][a_pos][0] = x;
gAirdrop[i][a_pos][1] = y;
//there is exception for Z, because we check the range in sphere and from center of object, we store the real Z value
//This is because when we don't store the real value, the player have to go up a bit in sky to pick the airdrop
gAirdrop[i][a_pos][2] = (z - (7.5));
//now make the airdrop existing
gAirdrop[i][a_exist] = true;
//set the timer to '-1', just for compactability
gAirdrop[i][a_expire_timer] = -1;
//set it as not dropped
gAirdrop[i][a_droped] = false;
return i;
}
}
return -1;
}
PARAMS:- x - x cordinate
- y - y cordinate
- * speed - speed at which the airdrop will fall from the sky
- * height - the height from which the airdrop will be dropped
NOTE:- the expiretime is for a timer which will start when the airdrop is droped on the ground
- the params with * are non mandatory, they have a default value
Managing Airdrops
The airdrop has started its journey from sky. It will reach earth or San Andreas land soon.
So in order to take care of it and people to pick it, we will use
OnObjectMoved.
pawn Код:
public OnObjectMoved(objectid)
{
//looping through all airdrops
for(new i; i < MAX_AIRDROPS; i++)
{
//if the airdrop slot is occupied
//i.e. the airdrop exists
if(gAirdrop[i][a_exist])
{
//if the object id is that of airdrop
if(objectid == gAirdrop[i][a_object])
{
//from now the airdrop is on the ground and players can pick it
gAirdrop[i][a_droped] = true;
//start a timer after which the airdrop will be destroyed
//the interval here is 1 minute (60000 ms), You may use a custom value if you wish
gAirdrop[i][a_expire_timer] = SetTimerEx("OnAirdropExpire", (60 * 1000), false, "i", i);
}
}
}
return 1;
}
If you notice, i use a timer for each airdrop. Its the expire timer dude.
The interval can be set accordingly. After the timer has executed, the airdrop will be destroyed automatically.
Now lets declare the timer callback.
pawn Код:
forward OnAirdropExpire(airdropid);
public OnAirdropExpire(airdropid)
{
return 1;
}
Now lets add code to this. We will simply destroy the airdrop in here.
Destroying includes, destroyin the object, timer, and setting the array to false. So the airdrop slot is ready to be used again.
pawn Код:
forward OnAirdropExpire(airdropid);
public OnAirdropExpire(airdropid)
{
//the airdrop slot is empty now
gAirdrop[airdropid][a_exist] = false;
//seting the timer value to '-1' just for preventing collapses and bugs
gAirdrop[airdropid][a_expire_timer] = -1;
//finally destroy the airdrop object
DestroyObject(gAirdrop[airdropid][a_object]);
return 1;
}
Declaring Player Timer
You remember, we created a player timer in OnPlayerConnect. Now we will declare it in our script.
pawn Код:
forward OnPlayerTimeUpdate(playerid);
public OnPlayerTimeUpdate(playerid)
{
return 1;
}
This is just a simple declaration. Now we will add code in this.
The code will be just looping through all airdrops and then checking if the player in near one.
If so, the player will get a GameText saying a message to pick the airdrop using some key configuration.
You can also use textdraws or other methods in this.
pawn Код:
forward OnPlayerTimeUpdate(playerid);
public OnPlayerTimeUpdate(playerid)
{
//the player will be not allowed to pickup the airdrop while in a vehicle
if(! IsPlayerInAnyVehicle(playerid))
{
//looping through all airdrops
for(new i; i < MAX_AIRDROPS; i++)
{
//if the airdrop slot is occupied
//i.e. the airdrop exists
if(gAirdrop[i][a_exist])
{
//if the airdrop is on the ground, dropped
if(gAirdrop[i][a_droped])
{
//now using 'IsPlayerInRangeOfPoint', we will check if the player is near that airdrop
//The range is 5.0 and resonably fine. You may increase or decrease it if you wish
if(IsPlayerInRangeOfPoint(playerid, 5.0, gAirdrop[i][a_pos][0], gAirdrop[i][a_pos][1], gAirdrop[i][a_pos][2]))
{
//if the player is near the drop
//Show the message, i am using gametext
GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~b~~h~~h~~h~Press ~h~~k~~CONVERSATION_NO~ ~b~~h~~h~~h~to pick", 1000, 3);
//the gametext will display the player to pickup the drop using key N (KEY_NO), you may change it if you wish!
//break the loop
break;
}
}
}
}
}
return 1;
}
Pickuping the airdrop
Now the semi last part is picking up the airdrop.
This can be very easily done under
OnPlayerKeyStateChange.
We will simply detect the player key and then if the conditions apply, we give the player his reward and destroy the airdrop.
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
//when the player presses key N or KEY_NO
//if you have custom key, then kindly seet it here - (newkeys == <YOUR_KEY>)
if(newkeys == KEY_NO)
{
//the player will be not allowed to pickup the airdrop while in a vehicle
if(! IsPlayerInAnyVehicle(playerid))
{
//looping through all airdrops
for(new i; i < MAX_AIRDROPS; i++)
{
//if the airdrop slot is occupied
//i.e. the airdrop exists
if(gAirdrop[i][a_exist])
{
//if the airdrop is on the ground, dropped
if(gAirdrop[i][a_droped])
{
//now using 'IsPlayerInRangeOfPoint', we will check if the player is near that airdrop
//The range is 5.0 and resonably fine. You may increase or decrease it if you wish
if(IsPlayerInRangeOfPoint(playerid, 5.0, gAirdrop[i][a_pos][0], gAirdrop[i][a_pos][1], gAirdrop[i][a_pos][2]))
{
//if the player is near the drop...
//We will apply a picking animation just for realisticity :)
ApplyAnimation(playerid, "MISC", "pickup_box", 1.0, 1, 1, 1, 1, 0);
//the gametext showing the player is picking the drop
GameTextForPlayer(playerid, "~b~~h~~h~~h~Picking...", 2000, 3);
//now we will make a timer to destroy the airdrop after 2 seconds
//the anim will be ovver by then
KillTimer(gAirdrop[i][a_expire_timer]);
gAirdrop[i][a_expire_timer] = SetTimerEx("OnPlayerPickupAirdrop", 2000, false, "ii", playerid, i);
gAirdrop[i][a_droped] = false;
//break the loop
break;
}
}
}
}
}
}
return 1;
}
You may change the animation if you want. This is the animation i used:
pawn Код:
ApplyAnimation(playerid, "MISC", "pickup_box", 1.0, 1, 1, 1, 1, 0);
* Just remember to PRELOAD the animations.
Notice that here also i use a timer. But this is not a memory consumer. I just destroyed the expire timer and replaced it with picking up timer.
This is used because we use an animation to pickup the airdrop and after that anim is ended, the airdrop will be destroyed.
So declare the function:
pawn Код:
forward OnPlayerPickupAirdrop(playerid, airdropid);
public OnPlayerPickupAirdrop(playerid, airdropid)
{
return 1;
}
Now lets add code to this:
pawn Код:
forward OnPlayerPickupAirdrop(playerid, airdropid);
public OnPlayerPickupAirdrop(playerid, airdropid)
{
//clear the anims
ClearAnimations(playerid);
//now here you give him whatever you want
//You can use 'random' to give random items or whatever
//Give reward
// For example:
/*
GivePlayerWeapon(playerid, 31, 100);
GameTextForPlayer(playerid, "~b~~h~~h~~h~You found a ~w~~h~M4", 3000, 3);
*/
//we destroy the airdrop...
//the airdrop slot is empty now
gAirdrop[airdropid][a_exist] = false;
//seting the timer value to '-1' just for preventing collapses and bugs
gAirdrop[airdropid][a_expire_timer] = -1;
//finally destroy the airdrop object
DestroyObject(gAirdrop[airdropid][a_object]);
return 1;
}
You can now give the reward. See the example in the code.
Exiting
Now its very important to properly exit the code.
Taking care of:
- Airdrop objects
- Airdrop timers
- Player Timers
First lets exit the global airdrops. If you are using the airdrops in filterscript user
OnFilterScriptExit or if in a gamemode
OnGameModeExit.
We made use on
OnGameModeInit, so we'll use
OnGameModeExit.
pawn Код:
public OnGameModeExit()
{
//unload mapandreas plugin
MapAndreas_Unload();
//looping through all airdrops to destroy them
for(new i; i < MAX_AIRDROPS; i++)
{
//this means, the airdrop is non existing
gAirdrop[i][a_exist] = false;
//killing the timer
//no worry, we use '-1' when destroying them, so only the valid timers will be killed
KillTimer(gAirdrop[i][a_expire_timer]);
//finally destroy the airdrop object
if(IsValidObject(gAirdrop[i][a_object]))
{
DestroyObject(gAirdrop[i][a_object]);
}
}
return 1;
}
Because we had also created a player timer, its necessary to destroy it in
OnPlayerDisconnect. This will save memory.
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
//destroy the player timer
KillTimer(gAirdropTimer[playerid]);
return 1;
}
Finally, using airdrops!
Now we have our script ready to use, anywhere.
We can create airdrops in your gamemode, filterscript or includes.
For example:
The below code will create an airdrop when a player kills a player.
You see only few lines and one airdrop is ready to use!
pawn Код:
//example:
public OnPlayerDeath(playerid, killerid, reason)
{
if(killerid != INVALID_PLAYER_ID)
{
new Float:pos[3];
GetPlayerPos(killerid, pos[0], pos[1], pos[2]);
CreateAirdrop(pos[0], pos[1]);
}
return 1;
}
Overall Code
This is what you will get when pilling all the code lines or the tutorial.
pawn Код:
#include <a_samp>
#include <mapandreas>
#define MAX_AIRDROPS 100
enum AirdropEnum
{
//the object which will be created and moved
a_object,
//expire time after which the airdrop will be destroyed automatically
a_expire_timer,
//position where the airdrop will fall
Float:a_pos[3],
//just to check if the airdrop exists
bool:a_exist,
//this is used just in case no one picks up the airdrop while its in air
bool:a_droped
};
new gAirdrop[MAX_AIRDROPS][AirdropEnum];
new gAirdropTimer[MAX_PLAYERS];
public OnGameModeInit()
{
//initiating mapandreas plugin
MapAndreas_Init(MAP_ANDREAS_MODE_FULL);
//looping through all airdrops
for(new i; i < MAX_AIRDROPS; i++)
{
//this means, the airdrop is non existing
gAirdrop[i][a_exist] = false;
}
return 1;
}
public OnPlayerConnect(playerid)
{
//create a timer with interval of 1000 ms i.e. 1 second.
gAirdropTimer[playerid] = SetTimerEx("OnPlayerTimeUpdate", 1000, true, "i", playerid);
//the timer is repearing because we will need this every time to check the player!
//you can also have a custom interval. But i recommend 1 second
CreateAirdrop(0.0, 0.0);
return 1;
}
/*
PARAMS:
x - x cordinate
y - y cordinate
* speed - speed at which the airdrop will fall from the sky
* height - the height from which the airdrop will be dropped
NOTE:
- the expiretime is for a timer which will start when the airdrop is droped on the ground
- the params with * are non mandatory, they have a default value
*/
CreateAirdrop(Float:x, Float:y, Float:speed = 5.0, Float:height = 100.0)
{
//looping through all airdrops
for(new i; i < MAX_AIRDROPS; i++)
{
//this check is for checking if the airdrop is existing or not
if(! gAirdrop[i][a_exist])
{
//we have found an empty slot
//using mapandreas, we get the Z angle
new Float:z;
MapAndreas_FindZ_For2DCoord(x, y, z);
//we have just obtained our Z cordinate
//but the object will be placed from center and that will look like half in ground and half on ground
//So we add an additional value into Z for betterment :)
z += 7.5;
//now create the airdrop object, the X & Y cordinates are from params and the Z is from map andreas + our value
//For throwing the airdrop from an height, we will add 'height' param value to Z
gAirdrop[i][a_object] = CreateObject(18849, x, y, (z + height), 0.0, 0.0, 0.0);
//once the object is created in the air, we make it move towards the ground
//Here only the Z cordinate plays the role, we will move the object to the initial Z cordinate
//the 'speed' is from params
MoveObject(gAirdrop[i][a_object], x, y, z, speed);
//for storing the position where the object will be droped, we use our array
gAirdrop[i][a_pos][0] = x;
gAirdrop[i][a_pos][1] = y;
//there is exception for Z, because we check the range in sphere and from center of object, we store the real Z value
//This is because when we don't store the real value, the player have to go up a bit in sky to pick the airdrop
gAirdrop[i][a_pos][2] = (z - (7.5));
//now make the airdrop existing
gAirdrop[i][a_exist] = true;
//set the timer to '-1', just for compactability
gAirdrop[i][a_expire_timer] = -1;
//set it as not dropped
gAirdrop[i][a_droped] = false;
return i;
}
}
return -1;
}
public OnObjectMoved(objectid)
{
//looping through all airdrops
for(new i; i < MAX_AIRDROPS; i++)
{
//if the airdrop slot is occupied
//i.e. the airdrop exists
if(gAirdrop[i][a_exist])
{
//if the object id is that of airdrop
if(objectid == gAirdrop[i][a_object])
{
//from now the airdrop is on the ground and players can pick it
gAirdrop[i][a_droped] = true;
//start a timer after which the airdrop will be destroyed
//the interval here is 1 minute (60000 ms), You may use a custom value if you wish
gAirdrop[i][a_expire_timer] = SetTimerEx("OnAirdropExpire", (60 * 1000), false, "i", i);
}
}
}
return 1;
}
forward OnAirdropExpire(airdropid);
public OnAirdropExpire(airdropid)
{
//the airdrop slot is empty now
gAirdrop[airdropid][a_exist] = false;
//seting the timer value to '-1' just for preventing collapses and bugs
gAirdrop[airdropid][a_expire_timer] = -1;
//finally destroy the airdrop object
DestroyObject(gAirdrop[airdropid][a_object]);
return 1;
}
forward OnPlayerTimeUpdate(playerid);
public OnPlayerTimeUpdate(playerid)
{
//the player will be not allowed to pickup the airdrop while in a vehicle
if(! IsPlayerInAnyVehicle(playerid))
{
//looping through all airdrops
for(new i; i < MAX_AIRDROPS; i++)
{
//if the airdrop slot is occupied
//i.e. the airdrop exists
if(gAirdrop[i][a_exist])
{
//if the airdrop is on the ground, dropped
if(gAirdrop[i][a_droped])
{
//now using 'IsPlayerInRangeOfPoint', we will check if the player is near that airdrop
//The range is 5.0 and resonably fine. You may increase or decrease it if you wish
if(IsPlayerInRangeOfPoint(playerid, 5.0, gAirdrop[i][a_pos][0], gAirdrop[i][a_pos][1], gAirdrop[i][a_pos][2]))
{
//if the player is near the drop
//Show the message, i am using gametext
GameTextForPlayer(playerid, "~n~~n~~n~~n~~n~~b~~h~~h~~h~Press ~h~~k~~CONVERSATION_NO~ ~b~~h~~h~~h~to pick", 1000, 3);
//the gametext will display the player to pickup the drop using key N (KEY_NO), you may change it if you wish!
//break the loop
break;
}
}
}
}
}
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
//when the player presses key N or KEY_NO
//if you have custom key, then kindly seet it here - (newkeys == <YOUR_KEY>)
if(newkeys == KEY_NO)
{
//the player will be not allowed to pickup the airdrop while in a vehicle
if(! IsPlayerInAnyVehicle(playerid))
{
//looping through all airdrops
for(new i; i < MAX_AIRDROPS; i++)
{
//if the airdrop slot is occupied
//i.e. the airdrop exists
if(gAirdrop[i][a_exist])
{
//if the airdrop is on the ground, dropped
if(gAirdrop[i][a_droped])
{
//now using 'IsPlayerInRangeOfPoint', we will check if the player is near that airdrop
//The range is 5.0 and resonably fine. You may increase or decrease it if you wish
if(IsPlayerInRangeOfPoint(playerid, 5.0, gAirdrop[i][a_pos][0], gAirdrop[i][a_pos][1], gAirdrop[i][a_pos][2]))
{
//if the player is near the drop...
//We will apply a picking animation just for realisticity :)
ApplyAnimation(playerid, "MISC", "pickup_box", 1.0, 1, 1, 1, 1, 0);
//the gametext showing the player is picking the drop
GameTextForPlayer(playerid, "~b~~h~~h~~h~Picking...", 2000, 3);
//now we will make a timer to destroy the airdrop after 2 seconds
//the anim will be ovver by then
KillTimer(gAirdrop[i][a_expire_timer]);
gAirdrop[i][a_expire_timer] = SetTimerEx("OnPlayerPickupAirdrop", 2000, false, "ii", playerid, i);
gAirdrop[i][a_droped] = false;
//break the loop
break;
}
}
}
}
}
}
return 1;
}
forward OnPlayerPickupAirdrop(playerid, airdropid);
public OnPlayerPickupAirdrop(playerid, airdropid)
{
//clear the anims
ClearAnimations(playerid);
//now here you give him whatever you want
//You can use 'random' to give random items or whatever
//Give reward
// For example:
/*
GivePlayerWeapon(playerid, 31, 100);
GameTextForPlayer(playerid, "~b~~h~~h~~h~You found a ~w~~h~M4", 3000, 3);
*/
//we destroy the airdrop...
//the airdrop slot is empty now
gAirdrop[airdropid][a_exist] = false;
//seting the timer value to '-1' just for preventing collapses and bugs
gAirdrop[airdropid][a_expire_timer] = -1;
//finally destroy the airdrop object
DestroyObject(gAirdrop[airdropid][a_object]);
return 1;
}
public OnGameModeExit()
{
//unload mapandreas plugin
MapAndreas_Unload();
//looping through all airdrops to destroy them
for(new i; i < MAX_AIRDROPS; i++)
{
//this means, the airdrop is non existing
gAirdrop[i][a_exist] = false;
//killing the timer
//no worry, we use '-1' when destroying them, so only the valid timers will be killed
KillTimer(gAirdrop[i][a_expire_timer]);
//finally destroy the airdrop object
if(IsValidObject(gAirdrop[i][a_object]))
{
DestroyObject(gAirdrop[i][a_object]);
}
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
//destroy the player timer
KillTimer(gAirdropTimer[playerid]);
return 1;
}
//example:
public OnPlayerDeath(playerid, killerid, reason)
{
if(killerid != INVALID_PLAYER_ID)
{
new Float:pos[3];
GetPlayerPos(killerid, pos[0], pos[1], pos[2]);
CreateAirdrop(pos[0], pos[1]);
}
return 1;
}
Re: How to make Airdrop system? (using Mapandreas) -
Excel™ - 09.06.2015
Pretty cuel!
I don't know if it makes any difference, but you can use ColAndreas plugin too. But this one is pretty accurate as well.
Maybe you find some little betterment with it?
Re: How to make Airdrop system? (using Mapandreas) -
Q_Lite - 12.06.2015
Nice man. Was searching for this for long.
Re: How to make Airdrop system? (using Mapandreas) - justice96 - 21.06.2015
Gammix. added more important things like (use (your key) to abort pickup the airdrop) and also players can be captured the airdrop with cmd like (/pickairdrop), don't forget to tell players that airdrop already dropped on the ground. Rep anyway!
Re: How to make Airdrop system? (using Mapandreas) -
Gammix - 21.06.2015
Aborting an airdrop isn't very realistic, how come a player swallow the drop by pressing a key!
And that command /pickairdrop can very easily be made from OnPlayerKeyStateChange.
Here is the snippet:
pawn Код:
CMD:pickairdrop(playerid)
{
//the player will be not allowed to pickup the airdrop while in a vehicle
if(! IsPlayerInAnyVehicle(playerid))
{
//looping through all airdrops
for(new i; i < MAX_AIRDROPS; i++)
{
//if the airdrop slot is occupied
//i.e. the airdrop exists
if(gAirdrop[i][a_exist])
{
//if the airdrop is on the ground, dropped
if(gAirdrop[i][a_droped])
{
//now using 'IsPlayerInRangeOfPoint', we will check if the player is near that airdrop
//The range is 5.0 and resonably fine. You may increase or decrease it if you wish
if(IsPlayerInRangeOfPoint(playerid, 5.0, gAirdrop[i][a_pos][0], gAirdrop[i][a_pos][1], gAirdrop[i][a_pos][2]))
{
//if the player is near the drop...
//We will apply a picking animation just for realisticity :)
ApplyAnimation(playerid, "MISC", "pickup_box", 1.0, 1, 1, 1, 1, 0);
//the gametext showing the player is picking the drop
GameTextForPlayer(playerid, "~b~~h~~h~~h~Picking...", 2000, 3);
//now we will make a timer to destroy the airdrop after 2 seconds
//the anim will be ovver by then
KillTimer(gAirdrop[i][a_expire_timer]);
gAirdrop[i][a_expire_timer] = SetTimerEx("OnPlayerPickupAirdrop", 2000, false, "ii", playerid, i);
gAirdrop[i][a_droped] = false;
//break the loop
break;
}
}
}
}
}
return 1;
}
And the message can be easily displayed when the airdrop is dropped on the ground, i.e. use SendClientMessage or anything else to notify players in
OnObjectMoved.
Re: How to make Airdrop system? (using Mapandreas) - justice96 - 21.06.2015
Yes, I know it. but, how to show the location name on SendClientMessage? or just create a new one at the top of script like random spawn {x,y,z} // location name
Ex: There's a airdrop at (location name)...
Re: How to make Airdrop system? (using Mapandreas) -
Gammix - 22.06.2015
I already gave you the key, use OnObjectMoved.
In order to detect the airdrop id, you may notice that i return the index in
CreateAirdrop. SO in order to detect the locations from ids, you can make vars for airdrops and use them in callback.
For example we are creating airdrop in BigEar.
Now create your airdrop anywhere like this:
pawn Код:
Airdrop_BigEar = CreateAirdrop(...);
Now in order to detect the airdrop has landed on the ground, use this:
pawn Код:
public OnObjectMoved(objectid)
{
//looping through all airdrops
for(new i; i < MAX_AIRDROPS; i++)
{
//if the airdrop slot is occupied
//i.e. the airdrop exists
if(gAirdrop[i][a_exist])
{
//if the object id is that of airdrop
if(objectid == gAirdrop[i][a_object])
{
if(i == Airdrop_BigEar)
{
SendClientMessageToAll(-1, "Airdroped at BigEar");
}
//from now the airdrop is on the ground and players can pick it
gAirdrop[i][a_droped] = true;
//start a timer after which the airdrop will be destroyed
//the interval here is 1 minute (60000 ms), You may use a custom value if you wish
gAirdrop[i][a_expire_timer] = SetTimerEx("OnAirdropExpire", (60 * 1000), false, "i", i);
}
}
}
return 1;
}
Re: How to make Airdrop system? (using Mapandreas) - justice96 - 22.06.2015
I know it, but. I never use 'mapandreas' to be server include & plugin. Better you tell me what is the function of mapandreas or the airdop will be spawned around san andreas? you forgot to add random rewards and can be claimed like this.
Код:
new rewards;
rewards = random(3);
switch(rewards)
{
case 0:
{
new cashrandom=random(15000);
GivePlayerCash(playerid,cashrandom);
SendClientMessage(playerid, COLOR_CYAN, "[INFO]: You have received a random cash.");
}
case 1:
{
new weaprandom = random(sizeof(WeaponsRandom));
GivePlayerWeapon(playerid, WeaponsRandom[weaprandom][0], WeaponsRandom[weaprandom][1]);
SendClientMessage(playerid, COLOR_CYAN, "[INFO]: You have received a random weapons.");
}
case 2:
{
SetPlayerArmour(playerid, 50.0);
SendClientMessage(playerid, COLOR_CYAN, "[INFO]: You have received a half armour.");
}
}
I forgot to share weapons random:
Код:
new const WeaponsRandom[][] =
{
// do something
};
Re: How to make Airdrop system? (using Mapandreas) -
Gammix - 22.06.2015
Without mapandreas, you can't find proper Z coordinates of airdrop so they would go under the ground or so on.
One method is by reading player positions and dropping an airdrop there, but that will be only applicable for players. You won't be able to drop it randomly anywhere.
Re: How to make Airdrop system? (using Mapandreas) - justice96 - 22.06.2015
I got it. thanks for the explanation
Re: How to make Airdrop system? (using Mapandreas) -
$$inSane - 10.07.2015
Been looking for an example of MapAndreas! Thnx