[Help]Bomb
#1

why all players get +5 score when bomb explode i want only for the one who set

+rep

Code:
#include <a_samp>
#define COLOR_RED 0xFF0000AA
#define COLOR_BLUE 0x0000BBAA
#define SCM




new PostaviTim[MAX_PLAYERS];
new PlantedBomb = 0;
new Explode;


public OnGameModeInit()
{
return 1;
}


public OnGameModeExit()
{
return 1;
}


public OnPlayerRequestClass(playerid, classid)
{
return 1;
}


public OnPlayerConnect(playerid)
{
    PostaviTim[playerid] = 0;
	return 1;
}


public OnPlayerDisconnect(playerid, reason)
{
PostaviTim[playerid] = 0;
return 1;
}


public OnPlayerSpawn(playerid)
{
	if (PostaviTim[playerid] == 0)
	{
	    new Tim = random(2);
	  	switch(Tim)
	   	{
	    	case 0:
	     	{
	     	    PostaviTim[playerid] = 1;
	     	    //SetPlayerSkin(playerid, ID Skina); // Ovo stavi ako hoces
	     	}
	     	case 1:
	     	{


	     	    PostaviTim[playerid] = 2;
	     	    //SetPlayerSkin(playerid, ID Skina); // Ovo stavi ako hoces
	     	}
	    }
    }
	return 1;
}


public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}


public OnVehicleSpawn(vehicleid)
{
return 1;
}


public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}


public OnPlayerText(playerid, text[])
{
return 1;
}


public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/plantbomb", cmdtext, true, 10) == 0)
	{
	    if (PostaviTim[playerid] == 2) return SendClientMessage (playerid, COLOR_RED, "Cops can't plant bomb");
		if (!IsPlayerInRangeOfPoint(playerid,2.0,212.9239,1820.3402,6.4216)) return SendClientMessage(playerid,COLOR_RED,"You are not in the place for planting the bomb");
		if (PlantedBomb == 1) return SendClientMessage(playerid,COLOR_RED,"The bomb is already planted!");
		PlantedBomb = 1;
		GameTextForAll("~r~Bomb has been planted!",3000,5);
		Explode = SetTimer("Explosion",300000,0);
	}


	if (strcmp("/defusebomb", cmdtext, true, 10) == 0)
	{
	    if (PlantedBomb == 0) return SendClientMessage(playerid,COLOR_RED,"The bomb is not planted!");
		if (PostaviTim[playerid] == 2)
		{
			if (!IsPlayerInRangeOfPoint(playerid,2.0,212.9239,1820.3402,6.4216)) return SendClientMessage(playerid,COLOR_RED,"You are not in the place for planting the bomb");
			SendClientMessage(playerid,COLOR_RED,"You are defusing a bomg, please wait.");
			SetTimer("Defusion",20000,0);
		}
		else
		{
			SendClientMessage (playerid, COLOR_RED, "Only cops can defuse bomb");
		}
	}
	return 0;
}
forward Explosion();
public Explosion()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        GivePlayerMoney(i, 10000);
		SetPlayerScore(i, GetPlayerScore(i) + 5);
		SendClientMessage(i, COLOR_RED, "Bomb:you got +5 score and 10000$ for planting bomb");
    }
	GameTextForAll("~r~Bomb exploded",6000,5);
	CreateExplosion(212.9239,1820.3402,6.4216,12,20.0);
    PlantedBomb = 0;
	return 1;
}
forward Defusion();
public Defusion()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        GivePlayerMoney(i, 10000);
		SetPlayerScore(i, GetPlayerScore(i) + 5);
		SendClientMessage(i, COLOR_RED, "Bomb:you got +5 score and 10000$ for defusing bomb");
    }
	KillTimer(Explode);
	GameTextForAll("~r~Bomb defused",6000,5);
	return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}


public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}


public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}


public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}


public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}


public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}


public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}


public OnRconCommand(cmd[])
{
return 1;
}


public OnPlayerRequestSpawn(playerid)
{
return 1;
}


public OnObjectMoved(objectid)
{
return 1;
}


public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}


public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}


public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}


public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}


public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}


public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}


public OnPlayerExitedMenu(playerid)
{
return 1;
}


public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}


public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}


public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}


public OnPlayerUpdate(playerid)
{
return 1;
}


public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}


public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}


public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}


public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}


public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
return 1;
}


public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
Reply
#2

You have used the variable "i" and you defined it for MAX_PLAYERS, that is why all the players playing takes the 5 scores.
Reply
#3

how to fix it?
Reply
#4

Quote:
Originally Posted by Mijata
View Post
how to fix it?
Use this

pawn Code:
#include <a_samp>
#define COLOR_RED 0xFF0000AA
#define COLOR_BLUE 0x0000BBAA
#define SCM




new PostaviTim[MAX_PLAYERS];
new PlantedBomb = 0;
new Explode;
new SetpScore[MAX_PLAYERS];

public OnGameModeInit()
{
return 1;
}


public OnGameModeExit()
{
return 1;
}


public OnPlayerRequestClass(playerid, classid)
{
return 1;
}


public OnPlayerConnect(playerid)
{
    PostaviTim[playerid] = 0;
    SetpScore[playerid] = 0;
    return 1;
}


public OnPlayerDisconnect(playerid, reason)
{
PostaviTim[playerid] = 0;
SetpScore[playerid] = 0;
return 1;
}


public OnPlayerSpawn(playerid)
{
    if (PostaviTim[playerid] == 0)
    {
        new Tim = random(2);
        switch(Tim)
        {
            case 0:
            {
                PostaviTim[playerid] = 1;
                //SetPlayerSkin(playerid, ID Skina); // Ovo stavi ako hoces
            }
            case 1:
            {


                PostaviTim[playerid] = 2;
                //SetPlayerSkin(playerid, ID Skina); // Ovo stavi ako hoces
            }
        }
    }
    return 1;
}


public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}


public OnVehicleSpawn(vehicleid)
{
return 1;
}


public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}


public OnPlayerText(playerid, text[])
{
return 1;
}


public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/plantbomb", cmdtext, true, 10) == 0)
    {
        if (PostaviTim[playerid] == 2) return SendClientMessage (playerid, COLOR_RED, "Cops can't plant bomb");
        if (!IsPlayerInRangeOfPoint(playerid,2.0,212.9239,1820.3402,6.4216)) return SendClientMessage(playerid,COLOR_RED,"You are not in the place for planting the bomb");
        if (PlantedBomb == 1) return SendClientMessage(playerid,COLOR_RED,"The bomb is already planted!");
        PlantedBomb = 1;
        SetpScore[playerid] = 1;
        GameTextForAll("~r~Bomb has been planted!",3000,5);
        Explode = SetTimer("Explosion",300000,0);
    }


    if (strcmp("/defusebomb", cmdtext, true, 10) == 0)
    {
        if (PlantedBomb == 0) return SendClientMessage(playerid,COLOR_RED,"The bomb is not planted!");
        if (PostaviTim[playerid] == 2)
        {
            if (!IsPlayerInRangeOfPoint(playerid,2.0,212.9239,1820.3402,6.4216)) return SendClientMessage(playerid,COLOR_RED,"You are not in the place for planting the bomb");
            SendClientMessage(playerid,COLOR_RED,"You are defusing a bomg, please wait.");
            SetTimer("Defusion",20000,0);
        }
        else
        {
            SendClientMessage (playerid, COLOR_RED, "Only cops can defuse bomb");
        }
    }
    return 0;
}
forward Explosion();
public Explosion()
{
    new playerid;
    if(SetpScore[playerid] == 1)
    {
        SetPlayerScore(playerid, GetPlayerScore(playerid) + 5);
        SetpScore[playerid] = 0;
    }
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        GivePlayerMoney(i, 10000);
        SendClientMessage(i, COLOR_RED, "Bomb:you got +5 score and 10000$ for planting bomb");
    }
    GameTextForAll("~r~Bomb exploded",6000,5);
    CreateExplosion(212.9239,1820.3402,6.4216,12,20.0);
    PlantedBomb = 0;
    return 1;
}
forward Defusion();
public Defusion()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        GivePlayerMoney(i, 10000);
        SetPlayerScore(i, GetPlayerScore(i) + 5);
        SendClientMessage(i, COLOR_RED, "Bomb:you got +5 score and 10000$ for defusing bomb");
    }
    KillTimer(Explode);
    GameTextForAll("~r~Bomb defused",6000,5);
    return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}


public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}


public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}


public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}


public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}


public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}


public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}


public OnRconCommand(cmd[])
{
return 1;
}


public OnPlayerRequestSpawn(playerid)
{
return 1;
}


public OnObjectMoved(objectid)
{
return 1;
}


public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}


public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}


public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}


public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}


public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}


public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}


public OnPlayerExitedMenu(playerid)
{
return 1;
}


public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}


public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}


public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}


public OnPlayerUpdate(playerid)
{
return 1;
}


public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}


public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}


public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}


public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}


public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
return 1;
}


public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
EDIT: This must be the Explosion callback and you have to do the same on diffusion callback to get it working perfectly.

pawn Code:
forward Explosion();
public Explosion()
{
    new playerid;
    if(SetpScore[playerid] == 1)
    {
        SetPlayerScore(playerid, GetPlayerScore(playerid) + 5);
        SetpScore[playerid] = 0;
        GivePlayerMoney(playerid, 10000);
        SetPlayerScore(playerid, GetPlayerScore(i) + 5);
        SendClientMessage(playerid, COLOR_RED, "Bomb:you got +5 score and 10000$ for planting bomb");
    }
    GameTextForAll("~r~Bomb exploded",6000,5);
    CreateExplosion(212.9239,1820.3402,6.4216,12,20.0);
    PlantedBomb = 0;
    return 1;
}
Reply
#5

Code:
forward Defusion(playerid);
public Defusion(playerid)
{
        GivePlayerMoney(playerid, 10000);
	SetPlayerScore(playerid, GetPlayerScore(playerid) + 5);
	SendClientMessage(playerid, COLOR_RED, "Bomb:you got +5 score and 10000$ for defusing bomb");
	KillTimer(Explode);
	GameTextForAll("~r~Bomb defused",6000,5);
	return 1;
}
Try this ^^
Reply
#6

Change this:
PHP Code:
Explode SetTimer("Explosion",300000,0); 
to this:
PHP Code:
Explode SetTimerEx("Explosion",300000,0"i"playerid); 
And

this:
PHP Code:
forward Explosion();
public 
Explosion()
{
    new 
playerid;
    if(
SetpScore[playerid] == 1)
    {
        
SetPlayerScore(playeridGetPlayerScore(playerid) + 5);
        
SetpScore[playerid] = 0;
    }
    for(new 
0MAX_PLAYERSi++)
    {
        
GivePlayerMoney(i10000);
        
SendClientMessage(iCOLOR_RED"Bomb:you got +5 score and 10000$ for planting bomb");
    }
    
GameTextForAll("~r~Bomb exploded",6000,5);
    
CreateExplosion(212.9239,1820.3402,6.4216,12,20.0);
    
PlantedBomb 0;
    return 
1;

to this:
PHP Code:
forward Explosion(playerid);
public 
Explosion(playerid)
{
    
GivePlayerMoney(playerid10000);
    
SetPlayerScore(playeridGetPlayerScore(playerid) + 5);
    
SendClientMessage(playeridCOLOR_RED"Bomb:you got +5 score and 10000$ for planting bomb");
    
GameTextForAll("~r~Bomb exploded",6000,5);
    
CreateExplosion(212.9239,1820.3402,6.4216,12,20.0);
    
PlantedBomb 0;
    return 
1;

Reply
#7

Yes ATGOGGY, You are right. btw GetPlayerScore(i) "GetPlayerScore(playerid)"
Reply
#8

Quote:
Originally Posted by Airman123
View Post
Yes ATGOGGY, You are right. btw GetPlayerScore(i) "GetPlayerScore(playerid)"
Oh, sorry. You are right. Edited.
Reply
#9

i will try now
Reply
#10

work thanks + rep for all
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)