/repair cmd
#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


Messages In This Thread
/repair cmd - by buzers - 31.07.2011, 08:18
Re: /repair cmd - by MoroDan - 31.07.2011, 10:38

Forum Jump:


Users browsing this thread: 1 Guest(s)