Author Topic: War3:Skills  (Read 12202 times)

DisturbeD

  • Newbie
  • *
  • Posts: 39
  • Me fail English? That’s unpossible.
    • View Profile
    • Email
War3:Skills
« on: December 04, 2009, 08:37:48 PM »
Aloha,
made a few common Warcraft skills. I hope they are working and you find them useful  :P

Skills I got so far:
- Regeneration (+maxHP and Amount Param)
- Long Jump
- Respawn (+counter)
- Mole (+getRandomPlayer)

More are comming!

Code: [Select]
#pragma semicolon 1
#include <sourcemod>
#include <sdktools_stocks>

new int:LongJumpFlag[MAXPLAYERS+1];//Multiplier Var and Switch if a player has long jump
new int:RespawnFlag[MAXPLAYERS+1];//Counter to see if a player will be revived on death
new int:RegenHealthFlag[MAXPLAYERS+1];//Max HP to which a player can recover
new int:RegenAmountFlag[MAXPLAYERS+1];//How much HP is recovered

public Plugin:myinfo =
{
name = "Common WCS-Skills",
author = "DisturbeD",
description = "",
version = "1.0.0.0",
url = "http://war3source.com/"
};

public OnPluginStart()
{
HookEvent("player_death",PlayerDeathEvent);
HookEvent("player_jump",PlayerJumpEvent);
}

public PlayerDeathEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
new client=GetClientOfUserId(GetEventInt(event,"userid"));
if(RespawnFlag[client])
{
new float:origin[3];
GetEntPropVector(client, Prop_Send, "m_vecOrigin", origin);
CS_RespawnPlayer(client);
TeleportEntity(client, origin, NULL_VECTOR, NULL_VECTOR);
RespawnFlag[client]--;
}
}

public PlayerJumpEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
new client=GetClientOfUserId(GetEventInt(event,"userid"));
if(LongJumpFlag[client])
{
new Float:velocity[3]={0.0,0.0,0.0};
velocity[0]=GetEntDataFloat(client,GetVelocityOffset_0);
velocity[1]=GetEntDataFloat(client,GetVelocityOffset_1);
velocity[0]*=float(LongJumpFlag[client])*0.20;
velocity[1]*=float(LongJumpFlag[client])*0.20;
SetEntDataVector(client,BaseVelocityOffset,velocity[3],true);
}
}

public Action:War3_GiveRegeneration(any:client,float:delayloop,int:maxhp,int:regrate)
{
RegenHealthFlag[client]=maxhp;
RegenAmountFlag[client]=regrate;
CreateTimer(delayloop,RegenerationLoop,client,TIMER_REPEAT);
}

public Action:War3_GiveLongJump(any:client,int:amount)
{
LongJumpFlag[client]= amount;
}

public Action:War3_GiveRespawn(any:client,int:amount)
{
RespawnFlag[client]+= amount;
}

public Action:War3_GiveMole(any:client,float:delay,int:chance)
{
if(GetRandomInt(1,100)<=chance)
{
if(client)
{
new int:ClientTeam=GetClientTeam(client);
if(ClientTeam)
{
new int:RandPlayer=GetRandomPlayer(5-ClientTeam);
if(RandOpPlayer!=-1)
{
new Float:origin[3];
GetEntPropVector(RandPlayer, Prop_Send, "m_vecOrigin", origin);
if(ClientTeam=2)
SetEntityModel(client,"models/player/t_urban");
else
SetEntityModel(client,"models/player/ct_phoenix");

PrintToChat(client,"You will be teleported as a mole in %d seconds.", delay);
CreateTimer(delay,MoleTeleport,client,origin);
}
}
}
}
else
PrintToChat(client,"You failed becoming a mole.");


public Action:MoleTeleport(Handle:timer,any:client,float:origin[3])
{
if(IsPlayerAlive(client))
{
TeleportEntity(client, origin, NULL_VECTOR, NULL_VECTOR);
}
CloseHandle(timer);
}
 
int:GetRandomPlayer(int:TeamID)
{
    new playerList[MAXPLAYERS];
    new playerCount;
   
    for (new i = 1; i <= MAXPLAYERS; i++)
    {
        if (GetClientTeam(i) != TeamID)
            continue;

        if (!IsClientInGame(i))
            continue;

        if(!IsPlayerAlive(i))
continue;

        playerList[playerCount] = i;
        playerCount++;
    }
    if (playerCount == 0)
        return -1;

    return playerList[GetRandomInt(0, playerCount-1)];
}

public Action:RegenerationLoop(Handle:timer,any:client)
{
if(RegenAmountFlag[client]&&RegenHealthFlag[client]&&GetClientHealth(client)<=RegenHealthFlag[client])
{
if(IsPlayerAlive(client)&&IsClientInGame(client))
{
new new_hp=GetClientHealth(client)+RegenAmountFlag[client];
if(new_hp>RegenHealthFlag[client])
SetEntityHealth(client,RegenAmountFlag[client]);
else
SetEntityHealth(client,new_hp);
}
else
{
RegenAmountFlag[client]=0;
CloseHandle(timer);
}
}
}
« Last Edit: December 04, 2009, 09:33:42 PM by DisturbeD »

DisturbeD

  • Newbie
  • *
  • Posts: 39
  • Me fail English? That’s unpossible.
    • View Profile
    • Email
Re: War3:Skills
« Reply #1 on: December 05, 2009, 05:23:22 AM »
I got an idea and I kinda like it  ;D:

Why not use the array system I used with the skills above for the most basic skills in warcraft too.

So for example:
If you want to increase a players damage output which is the case in most races, you just use client-arrays for
damage you want to add, the specific weapon and the chance to add the damage.
Additionally you use 1 array of bools (like:DidDamage) which is set to true, if the damage output was increased.

You create a func to give a player more damage: War3_GiveDamage(client, damage, weapon,chance)
and one to remove it again: War3_ResetDamage(client)

In case you got additional stuff to do in the same skill, you can just write it in the race file and check if DidDamage is
true and set it to false again...

You can use this system for so many skills, it would save lines, make it easier for beginners to code races, create more War3 commands,
make it easier to handle etc etc..
« Last Edit: December 05, 2009, 05:25:11 AM by DisturbeD »

DisturbeD

  • Newbie
  • *
  • Posts: 39
  • Me fail English? That’s unpossible.
    • View Profile
    • Email
Re: War3:Skills
« Reply #2 on: December 05, 2009, 08:24:21 AM »
Got bored so I just made the lil example for War3_GiveDamage:

Code: [Select]
#include <sourcemod>

new int:DamageAmount[MAXPLAYERS+1];
new int:DamageChance[MAXPLAYERS+1];
new string:DamageWeapon[MAXPLAYERS+1];//can be specific weapons, or a string like "weapon1,weapon2..."
new bool:DidDamage[MAXPLAYERS+1];

public Action:War3_GiveDamage(any:client,int:amount,int:chance,string:weapons[])
{
DamageAmount[client]=amount;
DamageChance[client]=chance;
copy(DamageWeapon, client, weapons);
}

public Action:War3_ResetDamage(any:client)
{
DamageAmount[client]=0;
DamageChance[client]=0;
copy(DamageWeapon, client, "");
}

public OnPluginStart()
{
HookEvent("player_hurt",PlayerHurtEvent);
}

public OnClientDisonnect(client)
{
War3_ResetDamage(client);
}

public PlayerHurtEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
new userid=GetEventInt(event,"userid");
new attacker_userid=GetEventInt(event,"attacker");
if(userid&&attacker_userid&&userid!=attacker_userid)
{
new client=GetClientOfUserId(attacker_userid);
new aclient=GetClientOfUserId(userid);
if(DamageAmount[client]&&GetRandomInt(1,100)<=DamageChance[client])
{
new weapon=GetEventString(event,"weapon");
if(DamageWeapon[client] == "all"||StrContains(DamageWeapon[client], weapon, false))
{
new int:health = GetEventInt(event, "health");
if(health>DamageAmount[client])
SetEntityHealth(aclient,health-DamageAmount[client]);
else
ForcePlayerSuicide(aclient);
new int:old_score=GetClientFrags(aclient);
SetEntProp(aclient, Prop_Data, "m_iFrags", old_score+1);
DidDamage[client] = true;//used to trigger other functions in racefiles
}
}
}
}

Dunno if it works, or if its faster than to write the same kind of code in each racefile, but in any case this small and simple piece of code saves tons of lines..
« Last Edit: December 05, 2009, 11:13:45 AM by DisturbeD »

stinkyfax

  • Full Member
  • ***
  • Posts: 120
    • View Profile
    • Email
Re: War3:Skills
« Reply #3 on: December 05, 2009, 09:12:44 AM »
it will not work.

DisturbeD

  • Newbie
  • *
  • Posts: 39
  • Me fail English? That’s unpossible.
    • View Profile
    • Email
Re: War3:Skills
« Reply #4 on: December 05, 2009, 09:17:33 AM »
telling where the bugs lie would be a great help for me learning the language

stinkyfax

  • Full Member
  • ***
  • Posts: 120
    • View Profile
    • Email
Re: War3:Skills
« Reply #5 on: December 05, 2009, 10:06:18 AM »
telling where the bugs lie would be a great help for me learning the language
sure, but it's not bugged. I mean you wanted to edit event info about damage and you did it.
The problem is that it will not change damage amount actually.
Modifying damage itself is a bit harder and requires C++ extensions, I've been using Hacks extension for this.

DisturbeD

  • Newbie
  • *
  • Posts: 39
  • Me fail English? That’s unpossible.
    • View Profile
    • Email
Re: War3:Skills
« Reply #6 on: December 05, 2009, 11:16:03 AM »
well that shouldn be a problem... replaced seteventint with setentityhealth.. if there wasn anything else it should be working now..
but in general what about the idea itself?

stinkyfax

  • Full Member
  • ***
  • Posts: 120
    • View Profile
    • Email
Re: War3:Skills
« Reply #7 on: December 05, 2009, 01:00:34 PM »
well that shouldn be a problem... replaced seteventint with setentityhealth.. if there wasn anything else it should be working now..
but in general what about the idea itself?
gl giving entity negative hp  ;)

P.S. In general the idea is good, I'd call it "war3 library".
Though I don't think there is a point of integrating simple skills like longjump into something like arrays, or core of war3. But for sure there should be implemented damaging system, speed system, etc inside of core with natives included.
« Last Edit: December 05, 2009, 01:02:31 PM by stinkyfax »

Anthony Iacono

  • Lead Developer
  • Administrator
  • Full Member
  • *****
  • Posts: 136
  • Lets make it better.
    • MSN Messenger - anthonyiacono@gmail.com
    • View Profile
    • My Blog
    • Email
Re: War3:Skills
« Reply #8 on: December 05, 2009, 01:21:00 PM »
Inside War3Source_Interface.inc
Code: [Select]
/**
 * Gets the state of a certain immunity.
 * @param client: Client index
 * @param immunity: The immunity you want to check.
 * @return The return value will be 1 if they are immune, if 0 they aren't, if -1 then it failed.
 */
native War3_GetImmunity(client,War3Immunity:immunity);

/**
 * Sets if the player owns a specific item.
 * @param client: Client index
 * @param immunity: The immunity you want to set.
 * @param imm_state: The state of immunity, 1 if they are, 0 if they aren't.
 * @noreturn
 */
native War3_SetImmunity(client,War3Immunity:immunity,imm_state);

/**
 * Sets the speed for the player that is handled within the War3Source system, good for skills and items that set speed so you don't end up making the player slower.
 * Pass 1.0 as speed when they no longer should use the speed, make sure to do this when they no longer have the skill or item, or whatever.
 * @param client: Client index
 * @param speed: The speed you want to pass.
 * @param ID: Optional parameter, pass either race ID or shop item ID if you have multiple MaxSpeeds in your plugin
 * @noreturn
 */
native War3_SetMaxSpeed(client,Float:speed,ID=-1);

/**
 * Sets the gravity for the player that is handled within the War3Source system, good for skills and items that set gravity so you don't end up making the player jump lower.
 * Pass 1.0 as gravity when they no longer should use the gravity, make sure to do this when they no longer have the skill or item, or whatever.
 * @param client: Client index
 * @param gravity: The gravity you want to pass.
 * @param ID: Optional parameter, pass either race ID or shop item ID if you have multiple MinGravitys in your plugin 
 * @noreturn
 */
native War3_SetMinGravity(client,Float:gravity,ID=-1);

/**
 * Sets the alpha (visibility) for the player handled within the War3Source system, good for skills and items that set visibility so you don't end up making the player more visible than they should be.
 * Pass 255 to disable.
 * @param client: Client index
 * @param alpha: Alpha level, 255 being visible, 0 being invisible.
 * @param ID: Optional parameter, pass either race ID or shop item ID if you have multiple MinAlphas in your plugin 
 * @noreturn
 */
native War3_SetMinAlpha(client,alpha,ID=-1);
#define War3_SetMinVisibility War3_SetMinAlpha

/**
 * Overrides the speed for War3Source, useful for punishing them or whatever.
 * Pass 0.0 as speed when you want the War3Source system to take over again, make sure to do this when they are no longer supposed to follow!
 * @param client: Client index
 * @param speed: The speed you want to pass.
 * @param ID: Optional parameter, pass either race ID or shop item ID if you have multiple OverrideSpeeds in your plugin   
 * @noreturn
 */
native War3_SetOverrideSpeed(client,Float:speed,ID=-1);

/**
 * Overrides the gravity for War3Source, useful for punishing them or whatever.
 * Pass 0.0 as gravity when you want the War3Source system to take over again, make sure to do this when they are no longer supposed to follow!
 * @param client: Client index
 * @param gravity: The gravity you want to pass.
 * @param ID: Optional parameter, pass either race ID or shop item ID if you have multiple OverrideGravitys in your plugin 
 * @noreturn
 */
native War3_SetOverrideGravity(client,Float:gravity,ID=-1);

/**
 * Overrides the alpha (visibility) for War3Source, useful for punishing them or whatever.
 * Pass -1 to disable! Important!
 * @param client: Client index
 * @param alpha: 255 is 100% vis, 0 is 100% invis
 * @param ID: Optional parameter, pass either race ID or shop item ID if you have multiple OverrideAlphas in your plugin 
 * @noreturn
 */
native War3_SetOverrideAlpha(client,alpha,ID=-1);
#define War3_SetOverrideVisibility War3_SetOverrideAlpha

If you want more of these natives, let me know.

DisturbeD

  • Newbie
  • *
  • Posts: 39
  • Me fail English? That’s unpossible.
    • View Profile
    • Email
Re: War3:Skills
« Reply #9 on: December 05, 2009, 02:27:45 PM »
Yeah, Id like to code general skills like more damage, regeneration, longjump, evasion, mole,hp leeching, mirror damage, respawn, explosion on death, jetpack etc like shopmenu items, which you can give other players...
This is easier for beginners and saves lines...
more beginners = more advanced scripters = more custom races = better mod

If you like that idea and want to implement it, Id code all those skills with a lil bit help of you or stinkyfax ;)

well that shouldn be a problem... replaced seteventint with setentityhealth.. if there wasn anything else it should be working now..
but in general what about the idea itself?
gl giving entity negative hp  ;)

P.S. In general the idea is good, I'd call it "war3 library".
Though I don't think there is a point of integrating simple skills like longjump into something like arrays, or core of war3. But for sure there should be implemented damaging system, speed system, etc inside of core with natives included.

negative hp?  ??? where do I give players negative hp? players with negative hp suicide and the attacker gets 1 score.. pls help me tho if smth is missing :S

stinkyfax

  • Full Member
  • ***
  • Posts: 120
    • View Profile
    • Email
Re: War3:Skills
« Reply #10 on: December 05, 2009, 03:23:03 PM »
you said:
replace seteventint which is (event damage) with setentityhealth.

DisturbeD

  • Newbie
  • *
  • Posts: 39
  • Me fail English? That’s unpossible.
    • View Profile
    • Email
Re: War3:Skills
« Reply #11 on: December 05, 2009, 03:33:31 PM »
oh well.. no Im not that stupid.. didn mean 1to1 replacement.. just changed the method of setting health...
instead of changing the damage output, I change the health directly based on GetEventInt(event, "health")

just look in my source code.. its easier to understand that way  ;D