/repair cmd
#1

HI! How to create something like this?

Player1 ID:0 Skin:50
Player2 D:1 Skin:249

Player1 cmd:
/repair 0 -> You can't repair your car!
/repair 1 -> Player2 car fixed (Player1 money +150, Player2 money -150)
/repair 2 -> Invalid ID

P.s. I'm very bad at english so don't ask me any questions!

EDIT
Reply
#2

PHP Code:
#include <a_samp>
public OnPlayerCommandText(playeridcmdtext[])
{
    new 
string[128], cmd[128], tmp[128], idx;
     
cmd strtok(cmdtextidx);
     
    if(!
strcmp(cmd"/repair"true))
    {
        
tmp strtok(cmdtextidx);
        
        
// Conditions
        
if(!strlen(tmp))
            return 
SendClientMessage(playerid, -1"[USAGE]: /repair [playerid / name]");
        new 
targetid ReturnUser(tmp);
        if(!
IsPlayerConnected(targetid))
            return 
SendClientMessage(playerid, -1"[ERROR]: That player is not connected !");
        if(!(
playerid != targetid))
            return 
SendClientMessage(playerid, -1"[ERROR]: You can't repair yourself !");
        if(
GetPlayerState(targetid) != PLAYER_STATE_DRIVER)
            return 
SendClientMessage(playerid, -1"[ERROR]: That player is not a driver !");
        if(
GetPlayerMoney(targetid) < 150)
            return 
SendClientMessage(playerid, -1"[ERROR]: That player doesn't have 150$ !");
        new 
FloatvHPGetVehicleHealth(GetPlayerVehicleID(targetid), vHP);
        if(
vHP 995)
            return 
SendClientMessage(playerid, -1"[ERROR]: That player's vehicle it's aleardy repaired !");
            
        
// OK -> repair car
        
RepairVehicle(GetPlayerVehicleID(targetid));
        
format(string128"You repaired {DE5757}%s{FFFFFF}'s car for {EB3333}150{3FAA33}$ {FFFFFF}!"returnName(targetid));
        
SendClientMessage(playerid0xFFFFFFFFstring);
        
format(string128"Mechanic {DE5757}%s {FFFFFF}has repaired your car for {EB3333}150{3FAA33}$ {FFFFFF}!"returnName(playerid));
        
SendClientMessage(targetid0xFFFFFFFFstring);
    }
    return 
1;
}
// =============================================================================
returnName(playerid)
{
    new 
name[20];
    
GetPlayerName(playeridname20);
    return (
name);
}
IsNumeric(const string[])
{
    for (new 
0strlen(string); ji++)
    {
        if (
string[i] > '9' || string[i] < '0') return 0;
    }
    return 
1;
}
strtok(const string[], &index)
{
    new 
length strlen(string);
    while ((
index length) && (string[index] <= ' '))
    {
        
index++;
    }
    new 
offset index;
    new 
result[128];
    while ((
index length) && (string[index] > ' ') && ((index offset) < (sizeof(result) - 1)))
    {
        
result[index offset] = string[index];
        
index++;
    }
    
result[index offset] = EOS;
    return 
result;
}
ReturnUser(text[])
{
    new 
pos 0;
    while (
text[pos] < 0x21)
    {
        if (
text[pos] == 0) return INVALID_PLAYER_ID;
        
pos++;
    }
    new 
userid INVALID_PLAYER_ID;
    if (
IsNumeric(text[pos])) // Check whole passed string
    
{
        
userid strval(text[pos]);
        if (
userid >= && userid MAX_PLAYERS)
        {
            if(!
IsPlayerConnected(userid))
            {
                
userid INVALID_PLAYER_ID;
            }
            else
            {
                return 
userid// A player was found
            
}
        }
    }
    
    
// They entered [part of] a name or the id search failed (check names just incase)
    
new len strlen(text[pos]);
    new 
count 0;
    new 
name[MAX_PLAYER_NAME];
    for(new 
0MAX_PLAYERSi++)
    {
        if(!
IsPlayerConnected(i)) continue;
        
GetPlayerName(inamesizeof (name));
        if (
strcmp(nametext[pos], truelen) == 0// Check segment of name
        
{
            if (
len == strlen(name)) // Exact match
            
{
                return 
i;
            }
            else 
// Partial match
            
{
                
count++;
                
userid i;
            }
        }
    }
    if (
count != 1)
    {
        
userid INVALID_PLAYER_ID;
    }
    return 
userid// INVALID_USER_ID for bad return

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)