AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Help] Bomb Odds (https://forums.alliedmods.net/showthread.php?t=225468)

jezznar 09-05-2013 03:16

[Help] Bomb Odds
 
Hi,
First off, I'm a noob. so please. spare me.
I asked for help through the suggestion section but I guess
the one who replied didn't really have time so I was thinking of trying
it out. I have a VERY LIMITED knowledge of AMXX coding. But I do know
how to formulate logic on stuff but on another programming language.
so,
I'm basing my code on Defuse Mistake 1.4 code.
The main purpose of it is "Plant Mistake" so basically, the bomb will detonate on a random chance when planted.

I also tried to use [FAQ/Tutorial] CS Bomb Scripting as a reference.

can someone please help me?

P.S.
+credits goes to the creator of Defue Mistake 1.4: RedShift187


Code:

#include <amxmodx>
#include <fakemeta>


#define PLUGIN "Bomb Odds"
#define VERSION "1"
#define AUTHOR "jezznar"

#define C4PTmr 3

new pmistake


public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
   
    //read cvar for percentage mistake ~ percentage conversion later
    pmistake = register_cvar("pmistake","10")
   
    //Check map if it has a bombsite before registering events
    if(engfunc(EngFunc_FindEntityByString, -1, "classname", "func_bomb_target") > 0)
    {
        //function call when bomb plant is started
        register_event("BarTime", "planting_bomb", "be", "1=3")
        //function call when bomb explodes: cancel tasks
        register_logevent("task_cancel", 6, "3=Target_Bombed")
        //function call when c4 planting is cancelled: cancel tasks
        register_event("BarTime", "task_cancel", "b", "1=0")
    }
   
    return PLUGIN_HANDLED
}

public planting_bomb(id) {
    //new id = get_loguser_index()
    //get the username of the user index
    new pname[32]
    get_user_name(id,pname,32)
    new risk = get_pcvar_num(pmistake)
   
    //random chance generation
    new mistake = random_num(1, 100)
   
    //compare mistake if equal or less than risk
    //if true: c4 explosion
    if (mistake <= risk)
    {
        //converts mistake to percent then multiplies it to the
        //time needed to plant the bomb (around 3 seconds, C4PTmr)
        //time before explosion = mistake% * C4PTmr
        new time = mistake / 100 * C4PTmr
        set_task(float(time),"bomb_explosion",1234)   
        client_print(0,print_chat, "%s triggered the bomb to explode", pname)
        client_print(0,print_center, "%s triggered the bomb to explode", pname)
    }
   
    return PLUGIN_CONTINUE


public task_cancel()
{
    //cancels task of explosion
    remove_task(1234)
   
    return PLUGIN_CONTINUE
}

public bomb_explosion()
{
    new bombent = engfunc(EngFunc_FindEntityByString, -1, "model", "models/w_c4.mdl")
    set_pdata_float(bombent, 100, get_gametime())
   
    return PLUGIN_CONTINUE
}


Arkshine 09-05-2013 10:38

Re: [Help] Bomb Odds
 
register_event("BarTime", "planting_bomb", "be", "1=3")

BarTime is an event per player, so called on a specific player, here when a guy is planting the bomb.

So, the player's index is passed directly in the callback, meaning :

public planting_bomb() -> public planting_bomb( id )

Then you can remove get_loguser_index().

jezznar 09-05-2013 23:31

Re: [Help] Bomb Odds
 
Quote:

Originally Posted by Arkshine (Post 2028822)
register_event("BarTime", "planting_bomb", "be", "1=3")

BarTime is an event per player, so called on a specific player, here when a guy is planting the bomb.

So, the player's index is passed directly in the callback, meaning :

public planting_bomb() -> public planting_bomb( id )

Then you can remove get_loguser_index().

Thanks for the new learning and tip! and it worked No runtime errors found in the debug traces too.
*posted the new code above.

Code:

new pname[18]
get_user_name(id,pname,18)

and changed the code that displays who triggered it

Code:

client_print(0,print_chat, "%s triggered the bomb to explode", pname)
just one more problem, the code for explosion doesnt seem to force the bomb to
explode. I tried looking at the source code of Force C4 Explode but it seems that it used
another method in which it manipulates the whole environment and kills everybody within range
and I'm not sure how will I be able to reuse it. (sorry for the noobness)

do you have any suggestion or comment on what I can do to fix it? thanks in advance

dark_style 09-06-2013 03:43

Re: [Help] Bomb Odds
 
Just a note: pname should be 32, not 18.

jezznar 09-06-2013 04:19

Re: [Help] Bomb Odds
 
Quote:

Originally Posted by dark_style (Post 2029198)
Just a note: pname should be 32, not 18.

note taken thanks

by the way I think the problem about not being able to make it explode is because
the code:
Code:

public bomb_explosion()
{
    new bombent = engfunc(EngFunc_FindEntityByString, -1, "model", "models/w_c4.mdl")
    set_pdata_float(bombent, 100, get_gametime())
   
    return PLUGIN_CONTINUE
}

is trying to find the c4 identity and make it explode. so the initial requirement would have been to
have the bomb be planted first. I tried rework it using RadiusDamage from the Engine module but It doesnt seem to work

Code:

public planting_bomb(id) {
    //new id = get_loguser_index()
    new pname[32]
    get_user_name(id,pname,32)
    new bOrigin[3]
    get_user_origin(id,bOrigin,0)
    new risk = get_pcvar_num(pmistake)
    //random chance generation
    new mistake = random_num(1, 100)
   
    //compare mistake if equal or less than risk
    //if true: c4 explosion
    if (mistake <= risk)
    {
        //converts mistake to percent then multiplies it to the
        //time needed to plant the bomb (around 3 seconds, C4PTmr)
        //time before explosion = mistake% * C4PTmr
        //new time = mistake / 100 * C4PTmr
        set_task(0.3,"bomb_explosion",id,bOrigin)   
        client_print(0,print_chat, "%s triggered the bomb to explode", pname)
        client_print(0,print_center, "%s triggered the bomb to explode", pname)
    }
   
    return PLUGIN_CONTINUE


public bomb_explosion(bOrigin[3])
{
    new bombent = engfunc(EngFunc_FindEntityByString, -1, "model", "models/w_c4.mdl")
    set_pdata_float(bombent, 100, get_gametime())

   
    //EXPLOSION
    //convert bOrigin to floats
    new Float:bOrigin_f[3]
    for(new i = 0;i<3;i++)
    {
        bOrigin_f[i] = float(bOrigin[i])
    }   
    //damage on a radius
    RadiusDamage(bOrigin_f,100,100)

    return PLUGIN_HANDLED
}


GuskiS 09-06-2013 05:59

Re: [Help] Bomb Odds
 
Use native cs_set_c4_explode_time(index, Float:value); where value is gametime() + yourtime. So basicly, if player fails on planting, set timer to +1.0 and it will explode :)

ConnorMcLeod 09-07-2013 02:24

Re: [Help] Bomb Odds
 
Problem is that you are trying to find a planted bomb when bomber is planting, so you won't ever be able to find one as you come at the begining of the process.
Better to include <csx> and to use forward "bomb_planted"

Usage :
PHP Code:

public bomb_plantedplanter )
{
    
// search for planted c4 here


PHP Code:

    new pname[32]
    
get_user_name(id,pname,32

This is not correct, you can fill the name string array untill 31, better to use charsmax(pname) instead of 31, and more generally, so when you change an array size you don't have to edit more lines.
->
PHP Code:

    new pname[32]
    
get_user_name(idpnamecharsmax(pname)) 


Also, your bomb detection is not efficient enough considering some plugins may change the c4 model, better to check m_bIsC4 pdata for this :

PHP Code:

#include < amxmodx >
#include < engine >
#include < fakemeta >
#include < csx >

const m_bIsC4 385;

public 
bomb_plantedplanter )
{
    new 
c4 find_planted_c4();
    if( 
c4 )
    {
    }
}

find_planted_c4(iSearchAfter = -1)
{
    new 
grenade iSearchAfter;
    while( (
grenade find_ent_by_class(grenade"grenade")) )
    {
        if( 
get_pdata_bool(grenadem_bIsC4) )
        {
            return 
grenade;
        }
    }
    return 
0;


Note : get_pdata_bool native has been added in amxx1.8.3, you can find it here (not official yet) : http://www.amxmodx.org/snapshots.php
If you want to stick with amxx 1.8.2 for now, you can find get_pdata_bool stock here : http://forums.alliedmods.net/showpos...01#post1712101


I'm not sure, but for some reason csx module could send bomb_planted forward before the bomb is completely planted, so if the code doesn't work, use a delayed 0.1s task from bomb_planted in order to be able to retrieve correctly c4 index.

jezznar 09-11-2013 05:42

Re: [Help] Bomb Odds
 
sorry for not being able to reply to this thread after a long time. I have problems with my internet connection since I came here in China last Sunday. Anyway.

@Connor, Just as I have suspected. I will try your suggestion for finding bomb_planted sequence. and thanks for the new learning, I didnt know that
C4's were considered as grenades in cstrike. I guess I have to find some sort of a resource list
@GusKis, thanks I will also try that.

I will give you guys a feedback once I have finished coding and testing it


All times are GMT -4. The time now is 18:58.

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