Problem with cmd
#1

Medic can heal players who are not nearby him
Reply
#2

Код:
CMD:healplayer(playerid,params[])
{
  if(GetPlayerSkin(playerid) != 275) return SendClientMessage(playerid, -1, "You are not a medic");
 new id,Float:x,Float:y,Float:z,Float:Health,string[200],string2[200],string3[200],name[MAX_PLAYER_NAME],name2[MAX_PLAYER_NAME];
 if(sscanf(params,"u",id)) return SendClientMessage(playerid,-1,"USAGE: /heal [ID]");
 else if(gTeam[playerid] != gTeam[id]) return SendClientMessage(playerid,-1,"Why would you heal your enemies?");
 else if(id == playerid) return SendClientMessage(playerid,-1,"You can't heal yourself.");
 else if(medic[playerid] == 0) return SendClientMessage(playerid,-1,"You are not medic");
 else
 {
  GetPlayerPos(id,x,y,z);
  if(!IsPlayerInRangeOfPoint(id,2.0,x,y,z)) return SendClientMessage(playerid,-1,"The player is too far away from you.");
  GetPlayerHealth(id,Health);
  if(Health == 100) return SendClientMessage(playerid,-1,"This player's health is too high.");
  SetPlayerHealth(id,100);
  F_GivePlayerMoney(playerid,1500);
  SetPlayerScore(playerid,GetPlayerScore(playerid) +2);
  GetPlayerName(playerid,name,sizeof(name));
  GetPlayerName(id,name2,sizeof(name2));
  format(string,sizeof(string),"%s (%d) healed you.",name,playerid);
  format(string2,sizeof(string2),"You have healed %s (%d).",name2,id);
  format(string3,sizeof(string3),"%s (%d) has healed %s (%d) and recieved 1500$.",name,playerid,name2,id);
  SendClientMessage(id,-1,string);
  SendClientMessage(playerid,-1,string2);
  SendClientMessageToAll(-1,string3);
 }
 return 1;
}
Reply
#3

Bad way to set classes, i recommend you to declare a variable to store class and define classes
PHP код:
new pClass[MAX_PLAYERS]; 
PHP код:
#define ASSAULT 0
#define MEDIC 1
#define SNIPER 2
#define CLOSERANGE 3
#define PYROMAN 4
#define SPYKILLER 5 
PHP код:
OnDialogResponse...
//choosen assault...
pClass[playerid] = ASSAULT;
//ect 
PHP код:
//On Commands..
//Medic command example
//blabla
if(pClass[playerid] != MEDIC) return NotMedic.. 
Reply
#4

Quote:
Originally Posted by K0P
Посмотреть сообщение
Код:
CMD:healplayer(playerid,params[])
{
  if(GetPlayerSkin(playerid) != 275) return SendClientMessage(playerid, -1, "You are not a medic");
 new id,Float:x,Float:y,Float:z,Float:Health,string[200],string2[200],string3[200],name[MAX_PLAYER_NAME],name2[MAX_PLAYER_NAME];
 if(sscanf(params,"u",id)) return SendClientMessage(playerid,-1,"USAGE: /heal [ID]");
 else if(gTeam[playerid] != gTeam[id]) return SendClientMessage(playerid,-1,"Why would you heal your enemies?");
 else if(id == playerid) return SendClientMessage(playerid,-1,"You can't heal yourself.");
 else if(medic[playerid] == 0) return SendClientMessage(playerid,-1,"You are not medic");
 else
 {
  GetPlayerPos(id,x,y,z);
  if(!IsPlayerInRangeOfPoint(id,2.0,x,y,z)) return SendClientMessage(playerid,-1,"The player is too far away from you.");
  GetPlayerHealth(id,Health);
  if(Health == 100) return SendClientMessage(playerid,-1,"This player's health is too high.");
  SetPlayerHealth(id,100);
  F_GivePlayerMoney(playerid,1500);
  SetPlayerScore(playerid,GetPlayerScore(playerid) +2);
  GetPlayerName(playerid,name,sizeof(name));
  GetPlayerName(id,name2,sizeof(name2));
  format(string,sizeof(string),"%s (%d) healed you.",name,playerid);
  format(string2,sizeof(string2),"You have healed %s (%d).",name2,id);
  format(string3,sizeof(string3),"%s (%d) has healed %s (%d) and recieved 1500$.",name,playerid,name2,id);
  SendClientMessage(id,-1,string);
  SendClientMessage(playerid,-1,string2);
  SendClientMessageToAll(-1,string3);
 }
 return 1;
}
Now medic can heal players who are not nearby him (2 meters).
Reply
#5

This code was used:
pawn Код:
GetPlayerPos(id,x,y,z);
if(!IsPlayerInRangeOfPoint(id,2.0,x,y,z)) return SendClientMessage(playerid,-1,"The player is too far away from you.");
The player specified will always be in range of their own position. It should have been:
Код:
if(!IsPlayerInRangeOfPoint(playerid,2.0,x,y,z))
and check if the player is connected before using in arrays otherwise run time error 4 will occur.
Last, don't use 3 strings with size of 200 but re-format one string instead. Reduce the size as well as 144 is the max.
Reply
#6

How to add cooldown to this command, that player can use this every 2 minutes...
Reply
#7

pawn Код:
// global:
new gPlayer_CMDhealplayer[MAX_PLAYERS];

// OnPlayerConnect:
gPlayer_CMDhealplayer[playerid] = 0;

// command /healplayer:
if (gPlayer_CMDhealplayer[playerid] && gettime() < gPlayer_CMDhealplayer[playerid]) return ... // error
// if the command has been used before and the 2 minutes haven't been passed, return the error about every 2 minutes


// other checks..

// rest of code.. sending messages


gPlayer_CMDhealplayer[playerid] = gettime() + 120; // current time + 2 minutes
Reply
#8

Work but now when player get skin from this class after changing class he again have this skin for medic

Код:
    if(GetPlayerScore(playerid) < 50) return SendClientMessage(playerid,-1,"You must have at least 50 score to play in this class!"),ShowPlayerDialog(playerid,DIALOG_CLASS,DIALOG_STYLE_LIST,"Class selection:","{90FF19}Assault\n{90FF19}Medic{FFFFFF}(50 score required)\n{90FF19}Sniper{FFFFFF}(100 score required)\n{90FF19}Close range{FFFFFF}(300 score required)\n{90FF19}Pyroman{FFFFFF}(500 score required)\n{90FF19}Spy Killer{FFFFFF}(1000 score required)","Choose","");
    {
    SendClientMessage(playerid, -1,"{FFD900}[CLASS]{17E3CB} You have selected your class as {E31717}Medic.");
    medic[playerid] = 1;
    SetPlayerSkin(playerid, 275);
    GivePlayerWeapon(playerid,4,1);
    GivePlayerWeapon(playerid,22,100);
    GivePlayerWeapon(playerid,42,100);
	}
Reply
#9

When change class you must set other skin
Reply
#10

But why then i have onplayerrequestclass there i have skins for select
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)