AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Creating a task (https://forums.alliedmods.net/showthread.php?t=279007)

kapitana 02-13-2016 08:47

[HELP] Creating a task
 
Hello Alliedmodders,
I'm in a little need of scripting help creating a task ...
So .. what I'm trying to do is a task that gets the victim, attacker and the damage taken.
Here is an example:

set_task(0.2, "create_task", id+TASK_DAMAGE, attacker, damage, _, _, "b")

But I get an error every time I try to compile. If someone knows how to fix it .... please share
Thanks in advance

Spirit_12 02-13-2016 09:05

Re: [HELP] Creating a task
 
It would help, if you post the exact error message and compile log.

siriusmd99 02-13-2016 09:12

Re: [HELP] Creating a task
 
Quote:

Originally Posted by kapitana (Post 2392530)
Hello Alliedmodders,
I'm in a little need of scripting help creating a task ...
So .. what I'm trying to do is a task that gets the victim, attacker and the damage taken.
Here is an example:

set_task(0.2, "create_task", id+TASK_DAMAGE, attacker, damage, _, _, "b")

But I get an error every time I try to compile. If someone knows how to fix it .... please share
Thanks in advance

PHP Code:

native set_task(Float:time,const function[],id 0,const parameter[]="",len 0,const flags[]=""repeat 0); 

Because you can't send 2 arguments in this way , i mean attacker, damage. I tried myself once but it didn't work.You should use parameter[]="" instead, it's a string where you add your values .

So do this :

PHP Code:

new params[2]
param[0] =  attacker
param
[1] =  damage

set_task
(0.2"create_task"id+TASK_DAMAGEparams2__"b"

But damage shall be the same type as attacker , if it's float then you convert it to number :
damage = floatround(damage)

And then if you need damage as float, you just convert it back to float :

new Float:dmg = float(param[1])

kapitana 02-13-2016 09:16

Re: [HELP] Creating a task
 
Yea ... that helps very much ... thnx siriusmd99

klippy 02-13-2016 13:10

Re: [HELP] Creating a task
 
Quote:

Originally Posted by siriusmd99 (Post 2392543)
But damage shall be the same type as attacker , if it's float then you convert it to number :
damage = floatround(damage)

And then if you need damage as float, you just convert it back to float :

new Float:dmg = float(param[1])

You don't have to convert it, it's okay just to re-tag the variable to avoid the compiler warning. Doing it your way you are even truncating the fractional part of a float value, which is a data loss.

PHP Code:

public Player_TakeDamage(idinflictorattackerFloatdamagedamagetype) {
    new 
params[2];
    
params[0] = attacker;
    
params[1] = _:damage;

    
set_task(0.2"create_task"id TASK_DAMAGEparamssizeof(params), __"b");
}

public 
create_task(params[], taskid) {
    new 
attacker params[0];
    new 
Floatdamage Floatparams[1];


I know it seems unnatural, and that tags in Pawn can be confusing. That's why we all hate tags.


All times are GMT -4. The time now is 09:26.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.