16.03.2011, 16:56
Well, I can't port forward, so I can't exactly test this code... Therefore, i'm wondering if someone could tell me if this code would work; The objective: A classic hitman system - /contract, /givehit -> Kill.
I also created a test command, which showed my contract value, reason, and the contractee, which seems to be working.
pawn Код:
COMMAND:contract(playerid, params[])
{
new user, amount, contractreason[128], string[128];
if(sscanf(params, "uis[128]", user, amount, contractreason))
return SendClientMessage(playerid, grey, "[USAGE] /Contract <Player ID> <Contract Amount> <Reason>");
if(PVar[playerid][pFaction] == 2)
return SendClientMessage(playerid, red, "ERROR: {FFFFFF}Hitmen cannot place contracts.");
if(amount < 3000)
return SendClientMessage(playerid, red, "ERROR: {FFFFFF}Amount has to be higher than $3,000!");
if(GetPlayerMoney(playerid) < amount)
return SendClientMessage(playerid, red, "ERROR: {FFFFFF}You do not have enough money to place this contract.");
PVar[user][ContractAmount] += amount;
format(PVar[user][ContractedBy], MAX_PLAYER_NAME, "%s", pName(playerid));
format(PVar[user][ContractReason], 128, contractreason);
format(string, sizeof(string), "<Contract> %s has placed a contract on %s; Reason: %s", pName(playerid), pName(user), contractreason);
printf(string);
GivePlayerMoney(playerid, -amount);
return 1;
}
COMMAND:givehit(playerid, params[])
{
new user, hitman, string[128];
if(PVar[playerid][pFaction] == 2)
{
if(sscanf(params, "uu", user, hitman))
return SendClientMessage(playerid, grey, "[USAGE] /GiveHit <Player ID> <Hitman ID>");
ChasingHit[hitman] = user;
ChasingHit[user] = hitman;
format(string, sizeof(string), "{0FA0D1}Server: {FFFFFF}You have been assigned to kill {FF003F}%s{FFFFFF}.", pName(user));
SendClientMessage(hitman, white, string);
}
return 1;
}
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
new string[128];
if(PVar[playerid][ContractAmount] != 0)
{
if(PVar[killerid][pFaction] == 2)
{
if(ChasingHit[killerid] == playerid)
{
GivePlayerMoney(killerid, PVar[playerid][ContractAmount]/2);
GivePlayerMoney(playerid, -PVar[playerid][ContractAmount]/2);
PVar[playerid][ContractAmount] = 0;
format(PVar[playerid][ContractedBy], MAX_PLAYER_NAME, "Nobody");
ChasingHit[killerid] = 1000;
format(string, sizeof(string), "{0FA0D1}Server: {FFFFFF}You have been killed by a {FF003F}Hitman Agency {FFFFFF}member. You have lost {36B816}$%d{FFFFFF}!");
SendClientMessage(playerid, white, string);
format(string, sizeof(string), "{0FA0D1}Server: {FFFFFF}You have completed your {FF003F}contract{FFFFFF}. You have gained {36B816}$%d{FFFFFF}!");
SendClientMessage(killerid, white, string);
}
if(ChasingHit[playerid] == killerid)
{
if(PVar[killerid][pFaction] == 2)
{
GivePlayerMoney(playerid, -PVar[killerid][ContractAmount]/2);
GivePlayerMoney(killerid, PVar[killerid][ContractAmount]/2);
format(PVar[killerid][ContractedBy], MAX_PLAYER_NAME, "Nobody");
PVar[killerid][ContractAmount] = 0;
ChasingHit[playerid] = 1000;
format(string, sizeof(string), "{0FA0D1}Server: {FFFFFF}You have killed a {FF003F}Hitman Agency {FFFFFF}member. You have gained {36B816}$%d{FFFFFF}!");
SendClientMessage(killerid, white, string);
format(string, sizeof(string), "{0FA0D1}Server: {FFFFFF}You have failed your {FF003F}contract{FFFFFF}. You have lost {36B816}$%d{FFFFFF}!");
SendClientMessage(playerid, white, string);
}
}
}
}
PVar[killerid][pKills] += 1;
PVar[playerid][pDeaths] += 1;
return 1;
}
pawn Код:
COMMAND:test(playerid, params[])
{
new string[128];
format(string, sizeof(string), "Contract Amount: $%d | Contracted By: %s | Reason: %s", PVar[playerid][ContractAmount], PVar[playerid][ContractedBy], PVar[playerid][ContractReason]);
SendClientMessage(playerid, white, string);
return 1;
}