Help with Anti-Heli Blading
#1

Hello everyone, I'm trying to put a function in my script where if you drive a helicopters blade into someone, it would automatically destroy that helicopter. I tried this, by adding a new definition which is current veh and the helicopter reason on OnPlayerDeath which is 50, but it still didn't work. My helicopter was still there after I heli-bladed the person.

Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    new currentveh;
	if (reason == 50) DestroyVehicle(currentveh);
	{
	SendDeathMessage(killerid, playerid, reason);
	}
	return 1;
}
Reply
#2

You're missing some steps in your code.
You've created the variable 'currentveh', but you haven't actually assigned any value to it.
You haven't told the program that currentveh holds the data of your current vehicle. The code doesn't recognize names, you could have as well called it potato, it wouldn't have made any difference for the processing.

So, to actually make it hold the right value, let's turn it into this:
pawn Код:
new currentveh; // You had this one already
currentveh = GetPlayerVehicleID(playerid); // Here we go
{
   // Your code
}
return 1;
Now, what that extra line is doing, is that it tells your server to find out what the vehicle ID is from your vehicle. This is an unique ID for every vehicle in the entire server, used to identify them, kind of like a license plate.
Second, it tells the server to put that bit of information inside 'currentveh', so everytime currentveh is called, it's being redirected to that vehicle, that saves us from fetching the information every single time.
Now you can use currentveh to redirect to that specific vehicle, allowing you to do all sorts of things with it.

Hope this works, cheers!
Reply
#3

As above said, you need to define currentveh.
The problem is, he's getting the vehicleid of the player that was killed, not the player that killed him.
So, do this instead.

Код:
public OnPlayerDeath(playerid, killerid, reason)
{
	if (reason == 50);
	{
        new currentveh;
        currentveh = GetPlayerVehicleID(killerid);
        DestroyVehicle(currentveh);
	SendDeathMessage(killerid, playerid, reason);
        SendClientMessage(killerid, -1, "Heliblading is not allowed!");
	}
	return 1;
}
This code checks if the player (playerid) was killed by reason 50.
If so, it gets the killer (killerid)'s vehicleid, and destroys it.
It also sends him a client message saying Heliblading isn't allowed.
Reply
#4

Oh nice one Unfriendly, totally missed out on that haha.
Reply
#5

Quote:
Originally Posted by judothijs
Посмотреть сообщение
You're missing some steps in your code.
You've created the variable 'currentveh', but you haven't actually assigned any value to it.
You haven't told the program that currentveh holds the data of your current vehicle. The code doesn't recognize names, you could have as well called it potato, it wouldn't have made any difference for the processing.

So, to actually make it hold the right value, let's turn it into this:
pawn Код:
new currentveh; // You had this one already
currentveh = GetPlayerVehicleID(playerid); // Here we go
{
   // Your code
}
return 1;
Now, what that extra line is doing, is that it tells your server to find out what the vehicle ID is from your vehicle. This is an unique ID for every vehicle in the entire server, used to identify them, kind of like a license plate.
Second, it tells the server to put that bit of information inside 'currentveh', so everytime currentveh is called, it's being redirected to that vehicle, that saves us from fetching the information every single time.
Now you can use currentveh to redirect to that specific vehicle, allowing you to do all sorts of things with it.

Hope this works, cheers!
Quote:
Originally Posted by Unfriendly
Посмотреть сообщение
As above said, you need to define currentveh.
The problem is, he's getting the vehicleid of the player that was killed, not the player that killed him.
So, do this instead.

Код:
public OnPlayerDeath(playerid, killerid, reason)
{
	if (reason == 50);
	{
        new currentveh;
        currentveh = GetPlayerVehicleID(killerid);
        DestroyVehicle(currentveh);
	SendDeathMessage(killerid, playerid, reason);
        SendClientMessage(killerid, -1, "Heliblading is not allowed!");
	}
	return 1;
}
This code checks if the player (playerid) was killed by reason 50.
If so, it gets the killer (killerid)'s vehicleid, and destroys it.
It also sends him a client message saying Heliblading isn't allowed.
Thanks for the replies, but they didn't work. It either didn't compile or the helicopter didn't remove itself after I heli-bladed a player.
Reply
#6

pawn Код:
public onPlayerDeath(playerid, killerid, reason)
{
 if (reason == 50)
 {
   new currentveh;
   currentveh = GetPlayerVehicleID(killerid);
   DestroyVehicle(currentveh);
   SendDeathMessage(killerid, playerid, reason);
   SendClientMessage(killerid, -1, "Heliblading is not allowed!");
 }
 return 1;
}
There were some typos in it, this should work
Reply
#7

Quote:
Originally Posted by judothijs
Посмотреть сообщение
pawn Код:
public onPlayerDeath(playerid, killerid, reason)
{
 if (reason == 50)
 {
   new currentveh;
   currentveh = GetPlayerVehicleID(killerid);
   DestroyVehicle(currentveh);
   SendDeathMessage(killerid, playerid, reason);
   SendClientMessage(killerid, -1, "Heliblading is not allowed!");
 }
 return 1;
}
There were some typos in it, this should work
Thanks, it works now.
Reply
#8

May I ask how that is different at all from what I posted?

Maybe I'm just blind but I don't see any difference, so what were the typos?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)