Needing help with a Equipment-from-Trunk-script. -
Chenjiang - 09.08.2011
Morning guys.
I'd like to add a small function to my server's PD regarding their equipment.
Unlike other server, on which you have kinda menu to take guns from (/equip), i want to add a /policetrunk.
What should it do?
a) check if the Player is a PD member (already done by me)
b) check if he is on duty (already done by me)
c) check if a police car is in range
e) open the policecars trunk
( GetVehicleParamsEx(Vehicle[playerid], engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(Vehicle[playerid], engine, lights, alarm, doors, bonnet, 1, objective); )
f) give player some weapons and maybe armour (can be doen by me with ease)
So, basically i need a loop, which checks what car is the closest one. and if it found one, it should check if its a policecar.
I use arrays to crate them, like those examples.
LSPDCAR [1] = CreateStaticVehicleEx(....)//a patrolcar
LSPDCAR [2] = CreateStaticVehicleEx(....)//a buffalo for fast response team
LSPDCAR [3] = CreateStaticVehicleEx(....)//a undercover vehicle
LSPDCAR [4] = CreateStaticVehicleEx(....)//a enforcer
and then it should return what car it is.
If it is car 1, it should open car 1's trunk and give the officer e.g. a shotgun.
else if its car 2, give him an mp5 and armour.
else if its car 3, give him camera and a silenced pistol.
else if its car 4, give him an m4 and kevlar...
and so on. You could jsu tmake a script with 2 cars, and i could add all the other copcars (i have 23 in total) by myself, if possible with a "else if" -command.
Код:
if(strcmp(cmd, "/policetrunk", true) == 0)
{
if(IsPlayerConnected(playerid))
{
if(PlayerInfo[playerid][pMember] == 3 || PlayerInfo[playerid][pLeader] == 3)
{
if(PlayerInfo[playerid][pDuty] == 1)
{
//check closest car
{
//if closest car is LSPDCAR [1]
{
//give player some stuff&open the cars trunk ill do that by myself later
}
//else if closest car is LSPDCAR [2]
{thesameshitthanabove}
//else (if its not a policecar at all)
{sendPlayerClientMessage(*randomparameters*,"You are not close to a LSPD Vehicle");
}
else
{
SendClientMessage(playerid, COLOR_GREY, "You are not on Duty.");
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, "You are not a Member of the LSPD.");
}
}
return 1;
}
yes i know the identiation sucks here, but i can fix that up later, it always gets kinda lacky when i copy/paste it from pawn to a forum.
Re: Needing help with a Equipment-from-Trunk-script. -
MadeMan - 09.08.2011
You need this function
pawn Код:
stock GetClosestVehicle(playerid)
{
new Float:x, Float:y, Float:z;
new Float:dist, Float:closedist=9999, closeveh;
for(new i=1; i < MAX_VEHICLES; i++)
{
if(GetVehiclePos(i, x, y, z))
{
dist = GetPlayerDistanceFromPoint(playerid, x, y, z);
if(dist < closedist)
{
closedist = dist;
closeveh = i;
}
}
}
return closeveh;
}
pawn Код:
if(strcmp(cmd, "/policetrunk", true) == 0)
{
if(PlayerInfo[playerid][pMember] == 3 || PlayerInfo[playerid][pLeader] == 3)
{
if(PlayerInfo[playerid][pDuty] == 1)
{
new vehicleid = GetClosestVehicle(playerid);
new Float:x, Float:y, Float:z;
GetVehiclePos(vehicleid, x, y, z);
if(IsPlayerInRangeOfPoint(playerid, 10.0, x, y, z)) // vehicle is within 10.0 radius
{
if(vehicleid == LSPDCAR[1])
{
//give player some stuff&open the cars trunk
}
else if(vehicleid == LSPDCAR[2])
{
//give player some stuff&open the cars trunk
}
else
{
SendClientMessage(playerid, COLOR_GREY, "You are not close to a LSPD Vehicle");
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, "You are not close to a car.");
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, "You are not on Duty.");
}
}
else
{
SendClientMessage(playerid, COLOR_GREY, "You are not a Member of the LSPD.");
}
return 1;
}
Quote:
Originally Posted by Chenjiang
yes i know the identiation sucks here, but i can fix that up later, it always gets kinda lacky when i copy/paste it from pawn to a forum.
|
Using [ pawn ] [ /pawn ] tags sometimes fixes it.
-
Chenjiang - 09.08.2011
thanks, you are awesome
its working perfectly and all, thx very much.
edit: i just noticed, if i try to compile, it gives me an error:
C:\Users\Dominic\Desktop\Music!\GTAM\gamemodes\gta-mods.pwn(924) : error 017: undefined symbol "GetPlayerDistanceFromPoint"
how can that be and how can i add it, since its a default SAMP funtion usually?
And somehow, although it works, i have to sit in the vehicle to ge tit to work. Its meant to work like that im in a radius of 10.0 AROUND the vehicle to work, i though (and your code looks like this, too) but somehow it will tell me 'you are not close to a car' always, when im not sitting directly IN the car as driver or passenger. and i already looked, there is no PlayerState with state 1/2 included in any of the stock functions (GetClosest vehicle, GetPlayerDistanceFrompoint and GetDistanceBetweenPoints) so i really dont know how to fix that issue.
Ђdit: sry 4 double-post, i wa smeant to click 'edit' but hit 'quote', maybe an admin can joint the two posts to one?