[Tutorial] Making simple hitman contract system[Zcmd,sscanf2]
#1

Hello guys. Today im going to show you how to make a simple hitman contract system. So, simply, all you have to do is do /hitman targetid ammount. If the targetid you hitted is dead, you will lost your money, and the killer id will get your money. Ight, so lets started.

All you have to do firstly, is add this to your top of script:
pawn Код:
new Hitman[MAX_PLAYERS];//For checking if the player has contract or not
new HitContract[MAX_PLAYERS];//Checking is player have a bounty or not
Ight, its time for script

pawn Код:
CMD:hitman(playerid,params[])
{
    new targetid,str[128],ammount,Name[MAX_PLAYER_NAME],Name2[MAX_PLAYER_NAME];//Creating variable for name
    if(sscanf(params,"ui",targetid,ammount))return SendClientMessage(playerid,-1,"Usage /hitman targetid ammount");//checking if the player uses wrong parameters
    if(GetPlayerMoney(playerid)<ammount)return SendClientMessage(playerid,-1,"You dont have enough money");//checking if the player doesnt have enough money
    Hitman[targetid] = 1;//Checking that the targetid has a contract
    GetPlayerName(playerid,Name,sizeof(Name));//self understandable
    GetPlayerName(targetid,Name2,sizeof(Name2));//self understandable
    format(str,sizeof(str),"%s[%d]has hitman contract %i on %s[%d]",Name,playerid,ammount,Name2,targetid);
    SendClientMessageToAll(-1,str);
    SetPVarInt(playerid,"hitmanmoney",ammount);//Saving the ammount of planted money into a variable which we are going later.
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(i==playerid)
        {
            HitContract[i] = 1;//Checking that player has planted a hitman
        }
    }
    return 1;
}
Ight, We've done in the command. Now what we want is, when our target is dead, the killer id will collect our money, and we will lost our money. We gotta use OnPlayerDeath callback function for this:

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    new str[128],Name[MAX_PLAYER_NAME],Name2[MAX_PLAYER_NAME];
    GetPlayerName(playerid,Name,sizeof(Name));
    GetPlayerName(killerid,Name2,sizeof(Name2));
    format(str,sizeof(str),"%s[%d]has collected money for killing hitman %s[%d]",Name2,killerid,Name,playerid);
    SendClientMessageToAll(-1,str);
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(HitContract[i] == 1)
        {
            GivePlayerMoney(killerid,GetPVarInt(i,"hitmanmoney"));//Giving killer id money
            GivePlayerMoney(i,GetPVarInt(i,"hitmanmoney"));
                        Hitman[playerid] = 0;//Setting the variable to 0, that means player doesnt have a contract exist anymore
        }
    }
    return 1;
}
Aight we have done here
I know this tutorial is simple.

Hope you guys liked it
Reply
#2

Pretty good :P!
Reply
#3

thank you!
Reply
#4

pawn Код:
Hitman[targetid] = 1;//Checking that the targetid has a contract
// Not Checking, its setting the targetid to hitman
-------------------------------------------------
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(i==playerid)
        {
            HitContract[i] = 1;//Checking that player has planted a hitman
        }
    }

// Why loop?? just add HitContract[playerid] = 1;
Reply
#5

Quote:
Originally Posted by newbie scripter
Посмотреть сообщение
pawn Код:
Hitman[targetid] = 1;//Checking that the targetid has a contract
// Not Checking, its setting the targetid to hitman
-------------------------------------------------
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(i==playerid)
        {
            HitContract[i] = 1;//Checking that player has planted a hitman
        }
    }

// Why loop?? just add HitContract[playerid] = 1;
yea sorry, was mistake.
thanks for the feedbacks anw
Reply
#6

How to also make a cmd that shows available contracts ?? ?
Reply
#7

Anyone ? Please I need IT
Reply
#8

Quote:
Originally Posted by rockhopper
Посмотреть сообщение
Anyone ? Please I need IT
Код:
CMD:checktarget(playerid,params[])
{
new targetid,str[128];
if(sscanf(params,"ui",targetid))return SendClientMessage(playerid,COLOR_WHITE,"Syntax:/checktarget id");
if (Hitman[targetid] == 1)
{
format(str,sizeof(str),"This guy has a bounty $%i",GetPVarInt(targetid,"hitmanmoney"));
SendClientMessage(playerid,COLOR_WHITE,str);
}
else return SendClientMessage(playerid,COLOR_WHITE,"This guy doesnt have any contracts exist");
return 1;
}
Reply
#9

But instead of target cant I see All Contracts such like :- Target :- Rockhopper Amount: 1
Target :- qazwsx Amount :- 1000
Like this ?
Reply
#10

PHP код:

CMD
:showcontrats(playeridparams[])
{
      if(
HitContract[playerid] < 1) return 1;
      new 
name[MAX_PLAYER_NAME+1];
      
SendClientMessage(playerid, -1"--------- List of the contracts -----------");
      foreach(new 
Player)
      {
            if(
Hitman[i]) GetPlayerName(inamesizeof(name)), SendClientMessage(playerid, -1"- Target : %s || Amount : %i"nameGetPVarInt(i"hitmanmoney"));
      }
      return 
1;

Reply
#11

Thanks Bro
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)