#1

i made a rob command and here is the code

PHP код:
CMD:rob(playeridparams[])
{
new 
targetid;
if(
sscanf(params"u"targetid)) return SendClientMessage(playeridCOLOR_WHITE"Usage: /rob [id]");
if(!
IsPlayerConnected(targetid)) return SendClientMessage(playeridCOLOR_RED"This player is not connected");
new 
Float:xFloat:yFloat:z;
new 
tPos GetPlayerPos(targetidxyz);
if(!
IsPlayerInRangeOfPoint(playerid5xyz)) return SendClientMessage(playeridCOLOR_RED"This player is too far away");
if(
GetPlayerMoney(targetid) < 1000) return SendClientMessage(playeridCOLOR_RED"This player doesn't have enough money");
new 
money GetPlayerMoney(targetid);
GivePlayerMoney(playeridmoney 10);
GivePlayerMoney(targetid, -money 10);
new 
name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
GetPlayerName(playeridnamesizeof(name));
new 
name2[MAX_PLAYER_NAME], string1[24+MAX_PLAYER_NAME];
GetPlayerName(targetidname2sizeof(name2));
format(string,sizeof(string),"%s has robbed %s",namename2);
SendClientMessage(playeridCOLOR_SILVER"You robbed %d"money);
SendClientMessage(targetidCOLOR_SILVER"You got robbed and lost %d"money/10);
SendClientMessageToAll(COLOR_GREEN,string);
return 
1;

It works but when i rob someone i doesn't send the amount of money in the chat it give the player the amount of money but i doesn't do in the chat

Reply
#2

pawn Код:
CMD:rob(playerid, params[])
{
    new targetid,name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME],string[50+MAX_PLAYER_NAME];
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /rob [id]");
    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "This player is not connected");
    new Float:x, Float:y, Float:z;
    new tPos = GetPlayerPos(targetid, x, y, z);
    if(!IsPlayerInRangeOfPoint(playerid, 5, x, y, z)) return SendClientMessage(playerid, COLOR_RED, "This player is too far away");
    if(GetPlayerMoney(targetid) < 1000) return SendClientMessage(playerid, COLOR_RED, "This player doesn't have enough money");
    new money = GetPlayerMoney(targetid);
    GivePlayerMoney(playerid, money / 10);
    GivePlayerMoney(targetid, -money / 10);
    GetPlayerName(playerid, name, sizeof(name));
    GetPlayerName(targetid, name2, sizeof(name2));
    format(string,sizeof(string),"%s has robbed %s",name, name2);
    SendClientMessageToAll(COLOR_GREEN,string);
    format(string,sizeof(string),"You robbed $%d", money/10);
    SendClientMessage(playerid,COLOR_SILVER,string);
    format(string,sizeof(string),"You got robbed and lost $%d", money/10);
    SendClientMessage(targetid,COLOR_SILVER,string);
    return 1;
}
try this
Reply
#3

What is new ?!
Reply
#4

1. Indentation
2.
pawn Код:
format(string,sizeof(string),"%s has robbed %s",name, name2);
SendClientMessage(playerid, COLOR_SILVER, "You robbed %d", money);
SendClientMessage(targetid, COLOR_SILVER, "You got robbed and lost %d", money/10);
SendClientMessageToAll(COLOR_GREEN,string);
You cannot format a client message, it has been replaced with:
pawn Код:
format(string,sizeof(string),"%s has robbed %s",name, name2);
    SendClientMessageToAll(COLOR_GREEN,string);
    format(string,sizeof(string),"You robbed $%d", money/10);
    SendClientMessage(playerid,COLOR_SILVER,string);
    format(string,sizeof(string),"You got robbed and lost $%d", money/10);
    SendClientMessage(targetid,COLOR_SILVER,string);
3. A little bit of a cleanup.
Reply
#5

This fromat is for SendClientMessageToAll
Reply
#6

yes, but you cannot format the SendClientMessage function. You must do the same as you did with SendClientMessageToAll, format the string, then send the string to the player via SendClientMessage(ToAll).
Reply
#7

Ok thank you but if i used the command many time the samp-server.exe crash and send me a message "The server is restarting" and doesn't do anything
Reply
#8

pawn Код:
CMD:rob(playerid, params[])
{
    new targetid,name[MAX_PLAYER_NAME], name2[MAX_PLAYER_NAME],string[60],Float:x, Float:y, Float:z;
    if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, COLOR_WHITE, "Usage: /rob [id]");
    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_RED, "This player is not connected");
    new tPos = GetPlayerPos(targetid, x, y, z);
    if(!IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z)) return SendClientMessage(playerid, COLOR_RED, "This player is too far away");
    if(GetPlayerMoney(targetid) < 1000) return SendClientMessage(playerid, COLOR_RED, "This player doesn't have enough money");
    else
    {
        new money = GetPlayerMoney(targetid);
        GivePlayerMoney(playerid, money / 10);
        GivePlayerMoney(targetid, -money / 10);
        GetPlayerName(playerid, name, sizeof(name));
        GetPlayerName(targetid, name2, sizeof(name2));
        format(string,sizeof(string),"%s has robbed %s",name, name2);
        SendClientMessageToAll(COLOR_GREEN,string);
        format(string,sizeof(string),"You robbed $%d", money/10);
        SendClientMessage(playerid,COLOR_SILVER,string);
        format(string,sizeof(string),"You got robbed and lost $%d", money/10);
        SendClientMessage(targetid,COLOR_SILVER,string);
    }
    return 1;
}
I tend to write commands in that style. Personally, I see nothing wrong, but if something is crashing your server, I recommend using crashdetect https://sampforum.blast.hk/showthread.php?tid=262796 to see what's causing the problem.
Reply
#9

I didn't use it before how to install it ?
Reply
#10

download the file, include <crashdetect> in your gamemode and filterscripts (if you have filterscripts), and in server.cfg, load the crashdetect plugin and start the server. If it crashes, check the server log file and paste the results here.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)