How do I script something like this?
#1

I want to make a /swat command that only works when someone is near a Enforcer.

How can I do that? What lines do I need to put in the beginning of the cmd script to accomplish that?

I DONT CARE ABOUT FACTIONS OR ANYTHING LIKE THAT, I just want the cmd to only work when ANYONE is near a Enforcer

Note: If it's easier to make the cmd only work when someone is INSIDE an Enforcer that is fine too
Reply
#2

This is the command I have so far that I only want to work when someone is near or inside an Enforcer.

PHP код:
CMD:swat(playeridparams[])
{
    
ShowPlayerDialog(playerid1DIALOG_STYLE_LIST"SWAT GEAR""Standard Gear\nAssault Rifle\nSniper Rifle\nSub Machine Gun\nPump Shotgun""Select""Cancel");
    return 
1;

It works fine in-game right now but I just want to make it not work unless someone is near or inside an Enforcer. Does anyone know how to do this?
Reply
#3

find nearest vehicle to player, if Enforcer is nearest one than let him use swat command like this

if Enforcer is nearest
Код:
CMD:swat(playerid, params[])
{
    if(GetVehicleModel(GetNearestVehicleToPlayer(playerid)) != Enforcer_Vehicle_Model) return SendClientMessage(playerid, -1, "you are not close to enforcer")
    return 1;
}
if player in Enforcer
Код:
CMD:swat(playerid, params[])
{
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "you are not inside Enforcer")
    if(GetVehicleModel(GetPlayerVehicleID(playerid)) != Enforcer_Vehicle_Model) return SendClientMessage(playerid, -1, "you need to Enforcer vehicle to use this command")
    return 1;
}
Reply
#4

Quote:
Originally Posted by iorp
Посмотреть сообщение
if Enforcer is nearest
Код:
CMD:swat(playerid, params[])
{
    if(GetVehicleModel(GetNearestVehicleToPlayer(playerid)) != Enforcer_Vehicle_Model) return SendClientMessage(playerid, -1, "you are not close to enforcer")
    return 1;
}
If I use this, will the command still work even if the Enforcer is not close to you? (but is still the nearest vehicle)
Reply
#5

Quote:
Originally Posted by aKnoxx
Посмотреть сообщение
If I use this, will the command still work even if the Enforcer is not close to you? (but is still the nearest vehicle)
if you use this code it will return message that "you are not close to enforcer" and stop execution. you can add your code below if player in near the Enforcer like this
Код:
CMD:swat(playerid, params[])
{
    if(GetVehicleModel(GetNearestVehicleToPlayer(playerid)) != Enforcer_Vehicle_Model) return SendClientMessage(playerid, -1, "you are not close to enforcer")
//your code if player is near the enforcer
    return 1;
}
Reply
#6

I got this error when I used that

grandlarc.pwn(744) : error 017: undefined symbol "GetNearestVehicleToPlayer"

CODE:
PHP код:
CMD:swat(playeridparams[])
{
    if(
GetVehicleModel(GetNearestVehicleToPlayer(playerid)) != Enforcer_Vehicle_Model) return SendClientMessage(playerid, -1"you are not close to enforcer"//line 744
    
ShowPlayerDialog(playerid1DIALOG_STYLE_LIST"SWAT GEAR""Standard Gear\nAssault Rifle\nSniper Rifle\nSub Machine Gun\nPump Shotgun\nDisarm\nChange Skin""Select""Cancel"); //line 745
    
return 1;

Reply
#7

Quote:
Originally Posted by aKnoxx
Посмотреть сообщение
I got these 2 errors when I used that

grandlarc.pwn(744) : error 017: undefined symbol "GetNearestVehicleToPlayer"
grandlarc.pwn(745) : error 001: expected token: ";", but found "-identifier-"

CODE:
PHP код:
CMD:swat(playeridparams[])
{
    if(
GetVehicleModel(GetNearestVehicleToPlayer(playerid)) != Enforcer_Vehicle_Model) return SendClientMessage(playerid, -1"you are not close to enforcer"//line 744
    
ShowPlayerDialog(playerid1DIALOG_STYLE_LIST"SWAT GEAR""Standard Gear\nAssault Rifle\nSniper Rifle\nSub Machine Gun\nPump Shotgun\nDisarm\nChange Skin""Select""Cancel"); //line 745
    
return 1;

this is the fix code
Код:
#include<EVF>
CMD:swat(playerid, params[])
{
	if(GetVehicleModel(GetNearestVehicleToPlayer(playerid)) != Enforcer_Vehicle_Model) return SendClientMessage(playerid, -1, "you are not close to enforcer"); //line 744
	ShowPlayerDialog(playerid, 1, DIALOG_STYLE_LIST, "SWAT GEAR", "Standard Gear\nAssault Rifle\nSniper Rifle\nSub Machine Gun\nPump Shotgun\nDisarm\nChange Skin", "Select", "Cancel"); //line 745
	return 1;
}
Reply
#8

Код:
if(GetVehicleModel(GetNearestVehicleToPlayer(playerid)) != Enforcer_Vehicle_Model) return SendClientMessage(playerid, -1, "you are not close to enforcer"); //line 744
Hey there, where is the checking for distance to that vehicle? You are missing part of the puzzle here.
Reply
#9

Quote:
Originally Posted by Pottus
Посмотреть сообщение
Код:
if(GetVehicleModel(GetNearestVehicleToPlayer(playerid)) != Enforcer_Vehicle_Model) return SendClientMessage(playerid, -1, "you are not close to enforcer"); //line 744
Hey there, where is the checking for distance to that vehicle? You are missing part of the puzzle here.
it will return the first nearest vehicle to player, but yes, in case of no vehicle around except Enforcer than also use distance condition for player to use the command only when player in range of vehicle.
Reply
#10

How do I add the distance condition to use the command only when player in range of vehicle?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)