[HELP] - Damage to object
#1

Hi everyone, I'm creating a to destroy tree system and I wanted the player to knock down the tree with the chainsaw, but it did not work...

Code:

Код:
public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid)
{
    if(GetPlayerWeapon(playerid) == 9)
    {
        if(IsPlayerInRangeOfPoint(playerid, 1.5, Trees[damagedid][0], Trees[damagedid][1], Trees[damagedid][2]))
        {
            Destroy[damagedid]++;
            PlayerPlaySound(playerid,1190,0.0,0.0,0.0);

            if(Destroy[damagedid] == 20)
            {
                Destroy[damagedid] = 0;
                DestroyDynamicObject(TreeObject[damagedid]);
                Trees[damagedid][0] = -1;
                Trees[damagedid][1] = -1;
                Trees[damagedid][2] = -1;
            }
        }
    }
And so test it too:

Код:
public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid)
{
    if(GetPlayerWeapon(playerid) == 9)
    {
        for(new i = 1; i <= MAX_TREES; i++)
        if(IsPlayerInRangeOfPoint(playerid, 1.5, Trees[i][0], Trees[i][1], Trees[i][2]))
        {
            Destroy[i]++;
            PlayerPlaySound(playerid,1190,0.0,0.0,0.0);

            if(Destroy[i] == 20)
            {
                Destroy[i] = 0;
                DestroyDynamicObject(TreeObject[i]);
                Trees[i][0] = -1;
                Trees[i][1] = -1;
                Trees[i][2] = -1;
            }
        }
    }
    return 1;
}
Reply
#2

This callback only works for damage inflicted to players. Objects don't have health and can't be damaged. You will have to use OnPlayerKeyStateChange or something.
Reply
#3

You must use OnPlayerKeyStateChange, detecting KEY_FIRE, with extra code in a timer.
Reply
#4

Use
PHP код:
public OnPlayerShootDynamicObject(playeridweaponidSTREAMER_TAG_OBJECT objectidFloat:xFloat:yFloat:z
Reply
#5

Quote:
Originally Posted by Jamester
Посмотреть сообщение
Use
PHP код:
public OnPlayerShootDynamicObject(playeridweaponidSTREAMER_TAG_OBJECT objectidFloat:xFloat:yFloat:z
Is it called with a chainsaw?
Reply
#6

Ah shit it does not, didn't read it fully!
Sorry Sick don't kill me
Reply
#7

Quote:
Originally Posted by Jamester
Посмотреть сообщение
Use
PHP код:
public OnPlayerShootDynamicObject(playeridweaponidSTREAMER_TAG_OBJECT objectidFloat:xFloat:yFloat:z
Quote:
Originally Posted by Jamester
Посмотреть сообщение
Ah shit it does not, didn't read it fully!
Sorry Sick don't kill me
No results, Sad, With the Desert Eagle It worked out

Код:
public OnPlayerShootDynamicObject(playerid, weaponid, STREAMER_TAG_OBJECT objectid, Float:x, Float:y, Float:z) 
{
    if(weaponid == 9)
    {
        for(new i = 1; i <= MAX_TREES; i++)
        if(IsPlayerInRangeOfPoint(playerid, 1.5, Trees[i][0], Trees[i][1], Trees[i][2]))
        {
            Destroy[i]++;
            PlayerPlaySound(playerid,1190,0.0,0.0,0.0);

            if(Destroy[i] == 20)
            {
                Destroy[i] = 0;
                DestroyDynamicObject(TreeObject[i]);
                Trees[i][0] = -1;
                Trees[i][1] = -1;
                Trees[i][2] = -1;
            }
        }
    }
    return 1;
}
Reply
#8

Quote:
Originally Posted by JhefTFJ
Посмотреть сообщение
No results, Sad, With the Desert Eagle It worked out

Код:
public OnPlayerShootDynamicObject(playerid, weaponid, STREAMER_TAG_OBJECT objectid, Float:x, Float:y, Float:z) 
{
    if(weaponid == 9)
    {
        for(new i = 1; i <= MAX_TREES; i++)
        if(IsPlayerInRangeOfPoint(playerid, 1.5, Trees[i][0], Trees[i][1], Trees[i][2]))
        {
            Destroy[i]++;
            PlayerPlaySound(playerid,1190,0.0,0.0,0.0);

            if(Destroy[i] == 20)
            {
                Destroy[i] = 0;
                DestroyDynamicObject(TreeObject[i]);
                Trees[i][0] = -1;
                Trees[i][1] = -1;
                Trees[i][2] = -1;
            }
        }
    }
    return 1;
}
Rwad my first post, that's one way you can do it.
Reply
#9

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Rwad my first post, that's one way you can do it.
I did that but it didn't work either.

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys == KEY_FIRE)
    {
	    if(GetPlayerWeapon(playerid) == 9)
	    {
	        for(new i = 1; i <= MAX_TREES; i++)
	        if(IsPlayerInRangeOfPoint(playerid, 1.5, Trees[i][0], Trees[i][1], Trees[i][2]))
	        {
	            Destroy[i]++;
	            PlayerPlaySound(playerid,1190,0.0,0.0,0.0);

	            if(Destroy[i] == 20)
	            {
	                Destroy[i] = 0;
	                DestroyDynamicObject(TreeObject[i]);
	                Trees[i][0] = -1;
	                Trees[i][1] = -1;
	                Trees[i][2] = -1;
	            }
	        }
	    }
	}
    return 1;
}
Reply
#10

That will give an array index out of bounds error because array indices start at 0 and end at size - 1; i.e. an array of size 5 has index slots 0 through 4. Also you mustn't be holding any other keys. If you're holding AIM when clicking then newkeys is not KEY_FIRE. It is KEY_FIRE combined with KEY_AIM. This has all been explained in great detail on the wiki page. Particularly the part titled "how NOT to check for a key".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)