Archived copy of war3source.com, the War3Source forum (2009–2020), rebuilt from the Internet Archive by wc3mods.net. This page was captured on 2012-10-24 (original capture). Forum · All archived topics · Wiki · Bug tracker · Blog
Chat

War3:Source
October 24, 2012, 03:24:26 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Download: http://war3source.com/index.php?board=9.0
What is War3Source?: http://war3source.com/index.php?topic=200.0
Sample Stats: http://war3source.com/war3stats
Steam Community Group: http://steamcommunity.com/groups/war3source
War3Source SVN Checkout: http://ownageclan.com/svn/war3source/
War3Source servers: http://www.game-monitor.com/search.php?vars=war3_version=
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Learn to script races  (Read 557 times)
Jaket
Newbie
*
Posts: 3


View Profile
« on: July 12, 2011, 08:29:30 PM »

Hey guys,

Not sure if this is in the right section of the forum, so apologies if it's not.

I'm interested in building races for w3s, but I'm not 100% sure if I'm going down the right track. I have a few years (2-3) programming in different languages, but never touched SourcePawn before so I looked over the introduction to that just to get familiar with the syntax used. I have set up my own local w3s server to test stuff out, and although I haven't started my own race I have made minor changes to existing races and tested just to know my server works.

What I'd really like to know is should I be putting w3s aside for now and working through SourceMod stuff (http://wiki.alliedmods.net/Category:SourceMod_Scripting) until I'm relatively clued up, or do you think I can just jump right into race building(since that's all I'm really interested in at this point) and learn that way?

Cheers for your time and advise,
Logged
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2045



View Profile WWW Email
« Reply #1 on: July 12, 2011, 08:42:37 PM »

look at the making a race tutorial http://war3source.com/index.php?board=7.0
and if you don't understand it then learn more sourcepawn first
Logged

DarkEnergy
Glider⠠⠵
Global Moderator
Sr. Member
*****
Posts: 413


⠠⠵


View Profile
« Reply #2 on: July 13, 2011, 11:36:44 AM »

I also started working on this with no knowledge of SourcePawn and a 5-6 year background on programming.

Best advice I can give you is: Look at other peoples scripts and learn from them. Look around the sourcemod forums for interesting plugins and try to transform them into skills. Best way to learn this stuff is just reading and understanding other peoples code, so I'd advise you to look at looooots of different plugins and how they work. Also it doesn't hurt to get in contact with a more experienced scripter and ask for help from time to time.
Logged

Jaket
Newbie
*
Posts: 3


View Profile
« Reply #3 on: July 15, 2011, 01:51:48 AM »

Hey again,

Thanks for your advise guys. I've looked into soucePawn a bit more and started scripting my own race. So far it's very basic: pretty much copy paste from other races as I build an understanding of how the functions work.

I've already run into a snag though, so I was hoping you guys could shed some light on the matter. Also if anyone is willing to share their steam ID with me so I could chat one on one when you're online about any issues I run into, that would be great as well!

Anyway the code is :

Code:
public OnWar3EventPostHurt(victim, attacker, damage){
if (ValidPlayer(victim) && ValidPlayer(attacker,true) && GetClientTeam(victim) != GetClientTeam(attacker)){
new race = War3_GetRace(attacker);
if(race==thisRaceID){
new skill_level=War3_GetSkillLevel(attacker,race,SKILL_DMG);

if (skill_level > 0 && !Hexed(victim,false)){
//new amt = LivingBullets[skill_level];
new amt = 50;

PrintToChat(attacker, "Your bullets feed, returning %d HP and extra damage!",amt);

//W3FlashScreen(attacker,RGBA_COLOR_GREEN);
War3_HealToBuffHP(attacker,amt);

//War3_DealDamage(victim, amt, attacker, _, "LivingBullet", W3DMGORIGIN_SKILL, W3DMGTYPE_PHYSICAL);
War3_DealDamage(victim,amt,attacker,_,"criticalnade",W3DMGORIGIN_SKILL,W3DMGTYPE_TRUEDMG);
}
}
}
}

I have commented out a few lines just to help me test, so you can ignore those. But basically it all works up until the DealDamage function. When the server tries to run this is crashes. I have no idea why the DealDamage function is not working, as the code I have uncommented is almost word for word copy+paste from Orc critnade. I have tested Orc crit nade on my server and it works fine, so I'm totally at a loss!
Logged
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2045



View Profile WWW Email
« Reply #4 on: July 15, 2011, 08:03:44 AM »

do u see the message in chat first before it crashes?
Logged

DarkEnergy
Jaket
Newbie
*
Posts: 3


View Profile
« Reply #5 on: July 15, 2011, 08:24:57 AM »

I do not see any messages before it crashes, however when I comment out the DealDamage line of code it works perfectly. I receive the chat message and my health is increased by 50.

I will post my entire class so you can get a better look and test it for yourself if you want to. I also added some debugging prints just to test what's being processed at what time. If LivingBullets skill hasn't been leveled, the first 2 If statements are printed. As soon as LivingBullets is leveled and a shoot an enemy the game crashes with no prints to screen.

Code:
/**
* File: War3Source_DarkKnight.sp
* Description: Dark Knight race writtenf or War3Source.
* Author(s): Jaket
*/

#pragma semicolon 1

#include <sourcemod>
#include "W3SIncs/War3Source_Interface"


new thisRaceID;

new Float:BurningSteed[5]={1.0,1.1,1.15,1.2,1.3};
new LivingBullets[5]={0,2,4,6,8};
new Float:BlackArmour[5]={1.0,0.9,0.8,0.7,0.6};
new Float:Bury[5]={0.0,400.0,600.0,800.0,1000.0};


new SKILL_SPEED,SKILL_DMG,SKILL_ARMOUR,ULT_BURY;

public Plugin:myinfo =
{
name = "Race - Dark Knight",
author = "Jaket",
description = "The Dark Knight for War3Source.",
version = "1.0",
url = "http://war3source.com"
};


public OnPluginStart()
{

}

public OnWar3PluginReady(){

thisRaceID=War3_CreateNewRace("Dark Knight", "DarkKnight");
/*SKILL_SPEED=War3_AddRaceSkill(thisRaceID,"Burning Steed", "Your steed speeds your pursuit", false,4);
SKILL_DMG=War3_AddRaceSkill(thisRaceID,"Living Bullets", "Your bullets feed on the enemy, dealing damage and returning life",false,4);
SKILL_ARMOUR=War3_AddRaceSkill(thisRaceID,"Black Armour", "Your armour reduces physical damage",false,4);
ULT_BURY=War3_AddRaceSkill(thisRaceID,"Bury Him", "Bury your enemy alive",false,4);*/
SKILL_SPEED=War3_AddRaceSkill(thisRaceID,"Burning Steed", "SPEED", false,4);
SKILL_DMG=War3_AddRaceSkill(thisRaceID,"Living Bullets", "+DMG and LEECH LIFE",false,4);
SKILL_ARMOUR=War3_AddRaceSkill(thisRaceID,"Black Armour", "REDUCED DMG",false,4);
ULT_BURY=War3_AddRaceSkill(thisRaceID,"Bury Him", "BURY",false,4);

War3_CreateRaceEnd(thisRaceID);
}


public InitPassiveSkills(client){
if(War3_GetRace(client)==thisRaceID){
//Set Player's speed
new skilllevel_speed=War3_GetSkillLevel(client,thisRaceID,SKILL_SPEED);
new Float:speed=BurningSteed[skilllevel_speed];
War3_SetBuff(client,fMaxSpeed,thisRaceID,speed);
//Give this player a glock to use
GivePlayerItem(client,"weapon_glock");
PrintToChat(client, "DEBUG: InitPassiveSkills running");
}
}

public OnRaceChanged( client, oldrace, newrace)
{
if(newrace != thisRaceID){
War3_WeaponRestrictTo(client, thisRaceID, "");
W3ResetAllBuffRace( client, thisRaceID);
} else {
War3_WeaponRestrictTo(client, thisRaceID, "weapon_knife,weapon_glock");
InitPassiveSkills( client);
}
}

public OnWar3EventSpawn( client){
InitPassiveSkills(client);
}

public OnWar3EventPostHurt(victim, attacker, damage){
PrintToChat(attacker, "DEBUG: OnWar3EventPostHurt running:attacker");
if (ValidPlayer(victim) && ValidPlayer(attacker,true) && GetClientTeam(victim) != GetClientTeam(attacker)){
PrintToChat(attacker, "DEBUG: 1st If passed");
new race = War3_GetRace(attacker);
if(race==thisRaceID){
PrintToChat(attacker, "DEBUG: 2nd If passed");
new skill_level=War3_GetSkillLevel(attacker,race,SKILL_DMG);

if (skill_level > 0 && !Hexed(victim,false)){
PrintToChat(attacker, "DEBUG: 3rd If passed");
//new amt = LivingBullets[skill_level];
new amt = 50;

PrintToChat(attacker, "Your bullets feed, returning %d HP and extra damage!",amt);

//W3FlashScreen(attacker,RGBA_COLOR_GREEN);
War3_HealToBuffHP(attacker,amt);

//War3_DealDamage(victim, amt, attacker, _, "LivingBullet", W3DMGORIGIN_SKILL, W3DMGTYPE_PHYSICAL);
War3_DealDamage(victim,amt,attacker,_,"criticalnade",W3DMGORIGIN_SKILL,W3DMGTYPE_TRUEDMG);
}
}
}
}

public OnW3TakeDmgBulletPre(victim,attacker,Float:damage){
if(ValidPlayer(victim,true) && ValidPlayer(attacker) && GetClientTeam(victim)!=GetClientTeam(attacker))
{
if(War3_GetRace(victim)==thisRaceID)
{
new skill_level=War3_GetSkillLevel(victim,thisRaceID,SKILL_ARMOUR);
if(skill_level > 0 && !Hexed(victim,false)){

War3_DamageModPercent(BlackArmour[skill_level]);
}
}
}
}
Logged
Ownz
Developer
Administrator
Hero Member
*****
Posts: 2045



View Profile WWW Email
« Reply #6 on: July 15, 2011, 08:33:06 AM »

what if you leave out W3DMGORIGIN_SKILL,W3DMGTYPE_TRUEDMG); ??
Logged

DarkEnergy
Glider⠠⠵
Global Moderator
Sr. Member
*****
Posts: 413


⠠⠵


View Profile
« Reply #7 on: July 15, 2011, 09:54:36 AM »

You don't check if the victim is alive (You do ValidPlayer(victim) but it should be ValidPlayer(victim, true)), could that be it? Also my Steam page is in my signature, so just add me. I already got 5-10 people on my list that soley added me for programming advise with SourcePawn/Unrealscript %)
Logged

Glider⠠⠵
Global Moderator
Sr. Member
*****
Posts: 413


⠠⠵


View Profile
« Reply #8 on: July 15, 2011, 06:06:20 PM »

We worked this out via steam chat now... Solution was to change the damage event to OnW3TakeDmgBullet instead of OnWar3EventPostHurt. Seems like there was some nice recursive looping going on overflowing the stack Cool
Logged

Ownz
Developer
Administrator
Hero Member
*****
Posts: 2045



View Profile WWW Email
« Reply #9 on: July 16, 2011, 02:52:27 PM »

i dont see how that can happen when dealdamage doesnt count as retriggered by default
Logged

DarkEnergy
Glider⠠⠵
Global Moderator
Sr. Member
*****
Posts: 413


⠠⠵


View Profile
« Reply #10 on: July 16, 2011, 08:51:53 PM »

Feel free to compile the code and try it yourself. I could reproduce the error on L4D.
Logged

Ownz
Developer
Administrator
Hero Member
*****
Posts: 2045



View Profile WWW Email
« Reply #11 on: July 16, 2011, 08:59:30 PM »

i c, well duh all damages within a damage callback needs consideration of checking W3GetDamageIsBullet to stop reentrancy. gj
Logged

DarkEnergy
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!