detect if vehicle type is near? -
[LCG]TANKER - 20.11.2009
i know it is posible but im not to sure how to acculy do it. ive been looking at this that somone made a wile ago trying to figure out if i could modify it to have it detect vehicle id's but havent had much luck
what i want to do:
if a player is near a cargo truck and dose a command this happens
http://forum.sa-mp.com/index.php?topic=123014.0
Re: detect if vehicle type is near? -
[LCG]TANKER - 21.11.2009
bump as it was at page 4
Re: detect if vehicle type is near? -
Rac3r - 21.11.2009
Quick option would be to use a loop for MAX_VEHICLES, checking if GetVehicleModel = "cargo truck model id", then use the new 0.3 function, IsPlayerInRangeOfPoint to check if you're in range of that vehicle.
Below is an example, you need to change the CARGOTRUCK_MODEL_ID to the cargo truck model id.... ofc.
HOW_FAR also needs changing. It's a float so input something like 50.0.
pawn Код:
dcmd_cargotruck(playerid,params[])
{
for(new i;i<MAX_VEHICLES;i++)
{
if(GetVehicleModel(i) == CARGOTRUCK_MODEL_ID)
{
new Float:x,Float:y,Float:z,Float:a;
GetVehiclePos(i,x,y,z);
if(IsPlayerInRangeOfPoint(playerid, HOW_FAR, x,y,z)==true)
{
// yes a cargo truck is near you.
}
}
}
return 1;
}
Re: detect if vehicle type is near? -
[LCG]TANKER - 21.11.2009
thanks for the help on it, i got 2 warnings im not to sure if it makes a huge diffrence as i have never worked with dcmd before mind doing a quick lookover?
pawn Код:
C:\Documents and Settings\Mark\Desktop\SA-MP .3a Server\gamemodes\desertwindbase.pwn(58) : warning 213: tag mismatch
C:\Documents and Settings\Mark\Desktop\SA-MP .3a Server\gamemodes\desertwindbase.pwn(50) : warning 203: symbol is never used: "params"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
2 Warnings.
pawn Код:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
pawn Код:
dcmd_cargotruck(playerid,params[]) // warning
{
for(new i;i<MAX_VEHICLES;i++)
{
if(GetVehicleModel(i) == 433 || GetVehicleModel(i) == 455)
{
new Float:x,Float:y,Float:z;
GetVehiclePos(i,x,y,z);
if(IsPlayerInRangeOfPoint(playerid,10.0, x,y,z)==true) // warning
{
SendClientMessage(playerid,COLOR_GREEN,"Ammo Refilled!");
// ammo stuff
return 1;
}
else
{
SendClientMessage(playerid,COLOR_RED,"A cargo truck isn't close enought for you to refill ammo!");
return 1;
}
}
}
return 1;
}
pawn Код:
if(strcmp(cmd, "/ref", true) == 0 || strcmp(cmd, "/refill", true) == 0)
{
if(IsPlayerConnected(playerid))
{
dcmd(cargotruck,10,cmdtext);
return 1;
}
}
return 0;
Re: detect if vehicle type is near? -
FUNExtreme - 21.11.2009
dcmd can only be used as a command, put dcmd(cargotruck,10,etc under OnPlayerCommandText
Re: detect if vehicle type is near? -
[LCG]TANKER - 21.11.2009
it is under command text
Re: detect if vehicle type is near? -
Donny_k - 21.11.2009
Add "#pragma unused params" to the bottom of your dcmd_*** command and remove the "== true" or swap it to "== 1" (it's not a boolean).
Re: detect if vehicle type is near? -
[LCG]TANKER - 22.11.2009
worked ty
Re: detect if vehicle type is near? -
[LCG]TANKER - 22.11.2009
ok, i got it all codded now, compiled fine but when i use it, it dosent work. it dosent send a unknown command message so its doing something not sure what is wrong