Anti-RDM script OnPlayerShootPlayer
#1

I'm trying stop players from killing civilians (No wanted levels) for no reason, I got to this point but i cant fix this.


ERRORS:
Код:
C:\Users\dank\Desktop\samp03\gamemodes\CCNR.pwn(754) : warning 217: loose indentation
C:\Users\dank\Desktop\samp03\gamemodes\CCNR.pwn(754) : warning 213: tag mismatch
C:\Users\dank\Desktop\samp03\gamemodes\CCNR.pwn(761) : warning 217: loose indentation
C:\Users\dank\Desktop\samp03\gamemodes\CCNR.pwn(762) : warning 225: unreachable code
C:\Users\dank\Desktop\samp03\gamemodes\CCNR.pwn(2308) : error 033: array must be indexed (variable "Player")
Script:
Код:
public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost)
{
	new team	= Player[Shooter][playerClass], 
		team2	= Player[Target][playerClass];
		
	new Float:health;
	GetPlayerHealth(Target, health);
	if(team == CIVILIAN && (team2 == ARMY || team2 == POLICE || team2 == FBI || team2 == CIA || team2 == SPY))
	{
		if(Player[Shooter][playerWanted] < 9)
		{
			setWanted(Shooter, 9);
		}
	}
	
	if((team == ARMY || team == POLICE || team == FBI || team == CIA || team == SPY) && team2 == CIVILIAN && Player[Target][playerWanted] == 0)
	{
		SetPlayerHealth(Target, floatadd(health, HealthLost));
		GameTextForPlayer(Shooter, "Don't attack innocent civilian.", 1000, 5);
	}

	if ( Shooter != INVALID_PLAYER_ID ) 
    { 
        if ( GetPlayerWantedLevel(Target) == 0) // check if the victim is from the same team as the shooter. 
        { 
 
            new Float:hp;
            GetPlayerHealth(Target, hp);
            SetPlayerHealth(Target, hp + HealthLost);
            SetPlayerHealth( Shooter, 0 );
            SendClientMessage( Shooter, COLOR_RED, "DONT KILL CIVILIANS!" ); 
            GivePlayerMoney( Shooter, - 5000 ); 
        }
    }
	return 1;
}
Thank You!
Reply
#2

ALWAYS provide full info, or no one cant help you...

Give us codes around line "754", "762" and "2308". and write its lines numbers
Reply
#3

Quote:
Originally Posted by Yousha
Посмотреть сообщение
ALWAYS provide full info, or no one cant help you...

Give us codes around line "754", "762" and "2308". and write its lines numbers
I don't care about the warnings, I can deal with them I just want to know what error 033: array must be indexed (variable "Player") means that's all, I'm not asking anyone to re-code a gamemode for me, just a diagnosis.
Reply
#4

Quote:
Originally Posted by Gnik
Посмотреть сообщение
I don't care about the warnings, I can deal with them I just want to know what error 033: array must be indexed (variable "Player") means that's all, I'm not asking anyone to re-code a gamemode for me, just a diagnosis.
Did you know if you have warnings,that your scripting wont work good.Or it will bug any other things in your gamemode
Reply
#5

Edit your team and team2 and make them per-player variables.

Код:
New team[MAX_PLAYERS];
And remove this 'Player[pla pla]'

And you can now use the same variable for both, shooter and target.

To check the shooter, you can use it like that;
Код:
team[Shooter] == Civilian // and etc.
For targets.
Код:
team[Target] == team // etc
But this team variable doesn't make sense for me to be honest, if you got a team system uses 'team' variable, why are you defining the team variable in the OnPlayerShootPlayer public function? It doesn't make any sense to me to be honest, the idea I gave should fix the errors but I'm completely sure that this anti RDM system will not work. However, run a check and leave me a reply if it didn't work.

Also make sure to fix your warnings, especially loose indentation warnings as they can cause lag
Reply
#6

I played around with the script and got it working, compiles perfectly with no warnings


It does what I want it to do so I am happy
Код:
public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost)
{
	new team	= Player[Shooter][playerClass], 
		team2	= Player[Target][playerClass];
		
	new Float:health;
	GetPlayerHealth(Target, health);
	if(team == CIVILIAN && (team2 == ARMY || team2 == POLICE || team2 == FBI || team2 == CIA || team2 == SPY))
	{
		if(Player[Shooter][playerWanted] < 9)
		{
			setWanted(Shooter, 9);
		}
	}
	
	if((team == ARMY || team == POLICE || team == FBI || team == CIA || team == SPY) && team2 == CIVILIAN && Player[Target][playerWanted] == 0)
	{
		SetPlayerHealth(Target, floatadd(health, HealthLost));
		GameTextForPlayer(Shooter, "Don't attack innocent civilian.", 1000, 5);
	}

	new wantedlevel;
	wantedlevel = GetPlayerWantedLevel(Target);
    if (wantedlevel == 0) // Check if the player has a wanted level = to 0
    { 

        new Float:hp;
        GetPlayerHealth(Target,hp); // Get the health of the player that is being shot at.
        SetPlayerHealth(Target,hp + HealthLost); // Replace the health of the player being shot.
        SetPlayerWantedLevel(Shooter,9); // Set the wanted level of the shooter to 9 stars.
        SetPlayerHealth( Shooter,0); // Set the health of the shooter to 0 so the player being shot so target can defend himself if needed.
        SendClientMessage( Shooter, COLOR_RED,"DONT KILL CIVILIANS!"); 
        GivePlayerMoney( Shooter,-5000); // Take all the moneyz.
        GivePlayerMoney(Target,5000); // Give the money to the player being shot.
    } 
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)