SA-MP Forums Archive
GetPlayerHealth - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: GetPlayerHealth (/showthread.php?tid=90697)



GetPlayerHealth - nuriel8833 - 09.08.2009

I have this explsion command (/explosion):

pawn Код:
if(strcmp(cmd, "/explode", true) == 0)
    {
    if (!IsPlayerAdmin(playerid)) return 0;
        tmp = strtok(cmdtext, idx);
        giveplayerid = ReturnUser(tmp);
        if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /explode [playerid/PartOfName] [reason]");
        if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "This command is exploding a player");
        if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "It creats an explosion on a player");
        if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Its helping to find cheaters,and just explode for fun");
        if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Warn!- also people around the player that exploded will hurt too!");
        if(giveplayerid != INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Warning!: Wrong ID/Player is not connected");
    GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
        GetPlayerName(playerid, sendername, sizeof(sendername));
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' '))
        {
            idx++;
        }
        new offset = idx;
        new result[64];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
        {
            result[idx - offset] = cmdtext[idx];
            idx++;
        }
        result[idx - offset] = EOS;
        if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /explode [playerid/PartOfName] [reason]");
        if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "This command is exploding a player");
        if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "It creats an explosion on a player");
        if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "Its helping to find cheaters,and just explode for fun");
    if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "Warn!- also people around the player that exploded will hurt too!");
    new Float:HH;
        new Float:X,Float:Y,Float:Z;
        if(!IsPlayerInAnyVehicle(playerid))
        {
            SendClientMessageToAll(playerid, COLOR_YELLOW, string,"You have been explode %s(ID:%d)! %s has %d health remaning!", giveplayer, sendername, (result), HH);
            GetPlayerPos(giveplayerid, X, Y, Z);
            CreateExplosion(X, Y, Z, 10, 15.0);
        }
        else
        {
            SendClientMessageToAll(playerid, COLOR_YELLOW, string,"You have been explode %s(ID:%d)! %s has %d health remaning!", giveplayer, sendername, (result), HH);
            GetVehiclePos(GetPlayerVehicleID(giveplayerid), X, Y, Z);
            CreateExplosion(X, Y, Z, 4, 10.0);
        }
        return 1;
    }
HH = Player health after explosion

but i dont know where to put GetPlayerHealth(otherplayer, HH);
if before the CreateExplosion --> will probadly(is it how you spell it?) it will show the life before the explosion
if after CreateExplosion--> it will maybe do a random number / life before explosion

so where to put GetPlayerHealth(otherplayer, HH); so it will work?
tanks for helpers


Re: GetPlayerHealth - nuriel8833 - 10.08.2009

*bump*
now its really 12 hours
please help!!!!!


Re: GetPlayerHealth - WrathOfGenesis - 10.08.2009

Ok, from what i can see, that script wont work.

What do you want it to do exactly?


Re: GetPlayerHealth - nuriel8833 - 10.08.2009

Quote:
Originally Posted by WrathOfGenesis
Ok, from what i can see, that script wont work.

What do you want it to do exactly?
/explode command
but why wont it work?


Re: GetPlayerHealth - WrathOfGenesis - 10.08.2009

Код:
if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /explode [playerid/PartOfName] [reason]");
if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "This command is exploding a player");
if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "It creats an explosion on a player");
if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "Its helping to find cheaters,and just explode for fun");
if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "Warn!- also people around the player that exploded will hurt too!");
Returning a value ends the function

Код:
SendClientMessageToAll(playerid, COLOR_YELLOW, string,"You have been explode %s(ID:%d)! %s has %d health remaning!", giveplayer, sendername, (result), HH);
Too much data in this function

Код:
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
What does this do?

Also, i think theres a delay between the explosion being created and the player loosing health so i think you will need to put the message on a timer to check the players health after they explode.


Re: GetPlayerHealth - nuriel8833 - 10.08.2009

pawn Код:
if(strcmp(cmd, "/explode", true) == 0)
{
    if (!IsPlayerAdmin(playerid)) return 0;
  tmp = strtok(cmdtext, idx);
   giveplayerid = ReturnUser(tmp);
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /explode [playerid/PartOfName] [reason]");
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "This command is exploding a player");
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "It creats an explosion on a player");
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Its helping to find cheaters,and just explode for fun");
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Warn!- also people around the player that exploded will hurt too!");
 if(giveplayerid != INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Warning!: Wrong ID/Player is not connected");
  GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
new length = strlen(cmdtext);
if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /explode [playerid/PartOfName] [reason]");
if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "This command is exploding a player");
if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "It creats an explosion on a player");
if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "Its helping to find cheaters,and just explode for fun");
   if(!strlen(result)) return SendClientMessage(playerid, COLOR_GRAD2, "Warn!- also people around the player that exploded will hurt too!");
    new Float:HH;
new Float:X,Float:Y,Float:Z;
if(!IsPlayerInAnyVehicle(playerid))
{
SendClientMessageToAll(playerid, COLOR_YELLOW, string,"You have been explode %s(ID:%d)! %s has %d health remaning!", giveplayer, sendername, (result), HH);
GetPlayerPos(giveplayerid, X, Y, Z);
CreateExplosion(X, Y, Z, 10, 15.0);
}
else
{
SendClientMessageToAll(playerid, COLOR_YELLOW, string,"You have been explode %s(ID:%d)! %s has %d health remaning!", giveplayer, sendername, (result), HH);
GetVehiclePos(GetPlayerVehicleID(giveplayerid), X, Y, Z);
CreateExplosion(X, Y, Z, 4, 10.0);
}
return 1;
}
so i delete some of the code but now where to put GetPlayerHealth


Re: GetPlayerHealth - Woet - 10.08.2009

Stop scripting!
Either learn a lot or stop scripting, but you have around 100 topics with questions and they only get more stupid.
Scripting is not easy, it's very complicated, hard and you need at least a few brain cells to be able to.
Your topics go like 'here is my code, this is what I want, make it for me.. *bump**bump**bump* *topic locked*'.


This makes no sense:
Код:
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /explode [playerid/PartOfName] [reason]");
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "This command is exploding a player");
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "It creats an explosion on a player");
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Its helping to find cheaters,and just explode for fun");
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_GRAD2, "Warn!- also people around the player that exploded will hurt too!");
Returning stops the callback, all code behind it won't be executed

This makes no sense:
Код:
if(giveplayerid != INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "Warning!: Wrong ID/Player is not connected");
!= means IS NOT: if giveplayerid is not an invalid ID - say it's invalid

Код:
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
Not needed to put that at every command, use strok or use dcmd/scanf

Код:
if(!IsPlayerInAnyVehicle(playerid))
{
SendClientMessageToAll(playerid, COLOR_YELLOW, string,"You have been explode %s(ID:%d)! %s has %d health remaning!", giveplayer, sendername, (result), HH);
GetPlayerPos(giveplayerid, X, Y, Z);
CreateExplosion(X, Y, Z, 10, 15.0);
}
else
{
SendClientMessageToAll(playerid, COLOR_YELLOW, string,"You have been explode %s(ID:%d)! %s has %d health remaning!", giveplayer, sendername, (result), HH);
GetVehiclePos(GetPlayerVehicleID(giveplayerid), X, Y, Z);
CreateExplosion(X, Y, Z, 4, 10.0);
}
GetPlayerPos works either way, no need to check whether they are in a vehicle.

Код:
SendClientMessageToAll(playerid, COLOR_YELLOW, string,"You have been explode %s(ID:%d)! %s has %d health remaning!", giveplayer, sendername, (result), HH);
You didn't set the HH variable yet


Re: GetPlayerHealth - nuriel8833 - 10.08.2009

Yea whatever....
I took this script from some V-Admin that i found so dont blame me...........
the only thing that i add is the getplayerhealth
and if you want here is the code:
pawn Код:
new Float:HH;
so what,i know scripting do you have any problems?
do you have any problem i want to make sure the codes will work
i dont want a server with many bugs like i saw.
I want to be sure,i want to learn like everybody,I done care what you saying,i know i can script.

and....
I know also to learn from see what you add,what you fixed and else....
thats why im asking for the code,not because i want to finish with that,thats how i learn


Re: GetPlayerHealth - Woet - 10.08.2009

Please correct your code so it works, is clean and makes sense, then I'll tell you where to put GetPlayerHealth.


Re: GetPlayerHealth - nuriel8833 - 10.08.2009

Quote:
Originally Posted by Woet
Please correct your code so it works, is clean and makes sense, then I'll tell you where to put GetPlayerHealth.
I have a bug which no matter what id i put it says wrong id

modify:
here you go:
pawn Код:
if(strcmp(cmd, "/explode", true) == 0)
{
if (!IsPlayerAdmin(playerid)) SendClientMessage(playerid, COLOR_GRAD2, "You must be an admin to use this command!");
tmp = strtok(cmdtext, idx);
giveplayerid = ReturnUser(tmp);
if(!strlen(tmp)) SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /explode [playerid/PartOfName] [reason]");
if(!strlen(tmp)) SendClientMessage(playerid, COLOR_GRAD2, "This command is exploding a player");
if(!strlen(tmp)) SendClientMessage(playerid, COLOR_GRAD2, "It creats an explosion on a player");
if(!strlen(tmp)) SendClientMessage(playerid, COLOR_GRAD2, "Its helping to find cheaters,and just explode for fun");
if(!strlen(tmp)) SendClientMessage(playerid, COLOR_GRAD2, "Warn!- also people around the player that exploded will hurt too!");
if(giveplayerid= INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_RED, "Warning!: Wrong ID/Player is not connected");
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
new length = strlen(cmdtext);
if(!strlen(result)) SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /explode [playerid/PartOfName] [reason]");
if(!strlen(result)) SendClientMessage(playerid, COLOR_GRAD2, "This command is exploding a player");
if(!strlen(result)) SendClientMessage(playerid, COLOR_GRAD2, "It creats an explosion on a player");
if(!strlen(result)) SendClientMessage(playerid, COLOR_GRAD2, "Its helping to find cheaters,and just explode for fun");
if(!strlen(result)) SendClientMessage(playerid, COLOR_GRAD2, "Warn!- also people around the player that exploded will hurt too!");
new Float:HH;
new Float:X,Float:Y,Float:Z;
SendClientMessageToAll(playerid, COLOR_YELLOW, string,"You have been explode %s(ID:%d)! %s has %d health remaning!", giveplayer, sendername, (result), HH);
GetPlayerPos(giveplayerid, X, Y, Z);
CreateExplosion(X, Y, Z, 10, 15.0);
}
return 1;
}
I delete the isplayerinanyvehicle and i changed the !giveplayerid= INVALID_PLAYER_ID to giveplayerid= INVALID_PLAYER_ID
and i delete the return before every SendClientMessage
and i changed if (!IsPlayerAdmin(playerid)) return 0; to:
if (!IsPlayerAdmin(playerid)) SendClientMessage(playerid, COLOR_GRAD2, "You must be an admin to use this command!");


now is it will work?