SA-MP Forums Archive
[HELP] Creating a new command... - 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)
+--- Thread: [HELP] Creating a new command... (/showthread.php?tid=312036)



[HELP] Creating a new command... [STILL NEED HELP] - Da' J' - 19.01.2012

Hey again. I've created a command to get off from "auto-crack" (Automaticly sent in "CRACK" animation and frozen if health under 20).

Well, it compiles it with 2 new warnings, but no effect IG. Here's the warnings, and code:

[PAWNO]E:\SA-MP Offical Server\gamemodes\B-RP.pwn(45426) : warning 235: public function lacks forward declaration (symbol "GetUp")
E:\SA-MP Offical Server\gamemodes\B-RP.pwn(45429) : warning 202: number of arguments does not match definition[/PAWNO]

[PAWNO]public GetUp(playerid)
{
new cmd[256];
cmd = strtok(cmd);
if(strcmp(cmd, "/getup", true) == 0)
{
new Float:health;
GetPlayerHealth(playerid,health);
if(health <= 20)
{
SetPlayerHealth(playerid, 25);
TogglePlayerControllable(playerid,1);
}
}
return 1;
}
[/PAWNO]

P.S. If anyone is interested, you can add there a timer for /getup. (1,5 minutes timer) Not needed tho, but if want, go ahead!


Re: [HELP] Creating a new command... - milanosie - 19.01.2012

at linfe 45426 forward it

EXAMPLE
forward GivePlayerMoneyEx(playerid,ammount);
public GivePlayerMoneyEx(playerid,ammount);

so it would be
forward GetUp(playerid)
public GetUp(playerid)


Re: [HELP] Creating a new command... - Konstantinos - 19.01.2012

pawn Code:
public OnPlayerCommandText( playerid, cmdtext[ ] )
{
    if( strcmp( cmdtext, "/getup", true, 6 ) == 0 ) {
        SetTimerEx( "GetUp", 90000, 0, "i", playerid );
        return 1;
    }
    return 0;
}

forward GetUp( playerid );
public GetUp( playerid )
{
    new
        Float:health;

    GetPlayerHealth( playerid, health );
    if( health <= 20 ) {
        SetPlayerHealth( playerid, 25 );
        TogglePlayerControllable( playerid, 1 );
    }
    return 1;
}



Re: [HELP] Creating a new command... - milanosie - 19.01.2012

Quote:
Originally Posted by Dwane
View Post
pawn Code:
public OnPlayerCommandText( playerid, cmdtext[ ] )
{
    if( strcmp( cmdtext, "/getup", true, 6 ) == 0 ) {
        SetTimerEx( "GetUp", 90000, 0, "i", playerid );
        return 1;
    }
    return 0;
}

forward GetUp( playerid );
public GetUp( playerid )
{
    new
        Float:health;

    GetPlayerHealth( playerid, health );
    if( health <= 20 ) {
        SetPlayerHealth( playerid, 25 );
        TogglePlayerControllable( playerid, 1 );
    }
    return 1;
}
Thats basiclly an exact copy of what I siad.


Re: [HELP] Creating a new command... - Konstantinos - 19.01.2012

Quote:
Originally Posted by milanosie
View Post
Thats basiclly an exact copy of what I siad.
It's totally different, because you told him to add the forward but still that won't work
pawn Code:
forward GetUp(playerid);                          // <-
public GetUp(playerid)
{
    new cmd[256];
    cmd = strtok(cmd);
    if(strcmp(cmd, "/getup", true) == 0) {
        new Float:health;
        GetPlayerHealth(playerid,health);
        if(health <= 20) {
            SetPlayerHealth(playerid, 25);
            TogglePlayerControllable(playerid,1);
        }
    }
    return 1;
}
// Thats wrong because all the command inside the custom callback will be undefined symbols.



Re: [HELP] Creating a new command... - milanosie - 19.01.2012

Well I asumed he already defined it.


Re: [HELP] Creating a new command... - Da' J' - 19.01.2012

Well this went funny... My auto-crack is bugging possibly because of this.

My ID was 0 IG, and i were the only one abled to go in it, after lower than 20 HP. /getup, nonono, doesn't work. With any of those. O.o

pawn Code:
forward CheckHealth(playerid);
public CheckHealth(playerid)
{
    new Float:health;
    GetPlayerHealth(playerid,health);
    if(health <= 20)
    {
        ApplyAnimation(playerid, "ped", "KO_spin_L", 4.1, 1, 1, 1, 1, 1, 1);
        TogglePlayerControllable(playerid,0);
    }
    return 1;
}



Re: [HELP] Creating a new command... - mSp - 19.01.2012

pawn Code:
forward CheckHealth();
public CheckHealth()
{
for(new i = 0; i < MAX_PLAYERS; i++)
  {
    new Float:health;
    GetPlayerHealth(i,health);
    if(health <= 20)
     {
        ApplyAnimation(i, "ped", "KO_spin_L", 4.1, 1, 1, 1, 1, 1, 1);
        TogglePlayerControllable(i,0);
     }
   }
   return 1;
}
Not tested though..anyways would be better to use OnPlayerUpdate for health checking since it checks health very frequently


Re: [HELP] Creating a new command... - Da' J' - 19.01.2012

Quote:
Originally Posted by mSp
View Post
pawn Code:
forward CheckHealth();
public CheckHealth()
{
for(new i = 0; i < MAX_PLAYERS; i++)
  {
    new Float:health;
    GetPlayerHealth(i,health);
    if(health <= 20)
     {
        ApplyAnimation(i, "ped", "KO_spin_L", 4.1, 1, 1, 1, 1, 1, 1);
        TogglePlayerControllable(i,0);
     }
   }
   return 1;
}
Not tested though..anyways would be better to use OnPlayerUpdate for health checking since it checks health very frequently
Ok... We tested it with 2 people, and now it works for everyone. But one question - How the heck my character keeps doing the animation all the time? It spins like 2 times in a second.. I think it's because of this?
pawn Code:
HealthTimer = SetTimer("CheckHealth",500, true);
That's under OnGameModeInIt.


Re: [HELP] Creating a new command... - mSp - 19.01.2012

Quote:
Originally Posted by Da' J'
View Post
Ok... We tested it with 2 people, and now it works for everyone. But one question - How the heck my character keeps doing the animation all the time? It spins like 2 times in a second.. I think it's because of this?
pawn Code:
HealthTimer = SetTimer("CheckHealth",500, true);
That's under OnGameModeInIt.
Have you checked your applyanimation parameters?
https://sampwiki.blast.hk/wiki/ApplyAnimation

And btw if you're missing still missing the /getup cmd
pawn Code:
public OnPlayerCommandText( playerid, cmdtext[ ] )
{
    if( strcmp( cmdtext, "/getup", true, 6 ) == 0 ) {
        SetPlayerHealth(playerid, 25);
        ClearAnimations(playerid);
        TogglePlayerControllable(playerid,1);
        return 1;
    }
    return 0;
}