FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Making functions

 
Post new topic   Reply to topic    Drop Shock Forum Index -> Open Source
View previous topic :: View next topic  
Author Message
khaibar
Advanced


Joined: 14 Dec 2007
Posts: 1141

PostPosted: Thu Oct 25, 2012 6:46 am    Post subject: Making functions Reply with quote

Some random functions that will help more players participate in updates


insert_mod(player,mod): Takes the player id and the mod id and does what the following code does:
Code:
//Insert Mod
$sql  = "UPDATE mods SET m_".$mod_chance."=(m_".$mod_chance."+1) WHERE user_id=? ";
$res =& $db->query($sql, Array($effect->i_owner) );
if (DB::isError($res)) { ReportDBError($res); }


Function code:
Code:
function insert_mod($player_id,$mod_id)
{
   $sql  = "UPDATE mods SET m_".$mod_id."=(m_".$mod_id."+1) WHERE user_id=? ";
   $res =& $db->query($sql, Array($player_id) );
   if (DB::isError($res)) { ReportDBError($res); }
}


After function is added, new simplified code becomes:
Code:
insert_mod($effect->i_owner,$mod_chance);



So if you ever want to modify the code and add an event where a player is given a mod, you put the function inside the conditions of that event.

Something random (and not to be added), if you kill a bandit gat, you get explosive ammo:

Code:
if( ($unitdata[$weapon->target_id]["is_bandit"]=="Y") && ($unitdata[$weapon->target_id]["i_type_id"]==52) )
{
   insert_mod($weapon->i_owner,26);
}


That piece would be pasted inside the kill code. If the target unit is a bandit, and has the ID of a gat (52), player who killed it($weapon->i_owner has the id of the one who killed it) gets explosive ammo (which has id 26)


Hopefully i will make enough functions to reduce the ~9k script to something like 2k and to make it readable by non-programmers.
Back to top
View user's profile Send private message
maXDooom
Advanced


Joined: 07 Dec 2011
Posts: 757
Location: in perverted places

PostPosted: Thu Oct 25, 2012 6:50 am    Post subject: Reply with quote

didnt read anything but seams good #llort#
_________________
Walterohdim wrote:

I would be so mad I would Tomo Rage, and probably lose my mod ship and council seat.

Walterohdim
Back to top
View user's profile Send private message
Strawberry
Simple


Joined: 27 Jan 2010
Posts: 22

PostPosted: Thu Oct 25, 2012 8:30 pm    Post subject: Reply with quote

Also any internal comments would help more beginner coders. Although I don't know if you want to work on that instead of just doing a project khaibar.. just an idea : )

-SB
Back to top
View user's profile Send private message
khaibar
Advanced


Joined: 14 Dec 2007
Posts: 1141

PostPosted: Fri Oct 26, 2012 12:25 am    Post subject: Reply with quote

I was doing a project, then OS came up so I put it on hold

+ I am just too lazy >.<
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Drop Shock Forum Index -> Open Source All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group